for Loop

noun

say it: “FOR LOOP” /ˈfɔr ˈlup/

A loop that counts from a start to a finish, taking one step, such as adding or taking away one, each time round.

What is a for loop in PowerShell?

A for loop counts. Its parentheses hold three parts, separated by semicolons: a start that runs once, a test checked before every pass, and a step taken after each one. $n-- takes one off; $n++ adds one.

for ($n = 3; $n -ge 1; $n--) {
    "T-minus $n"
}
'Liftoff!'
# T-minus 3
# T-minus 2
# T-minus 1
# Liftoff!

In a sentence

  • “The launch countdown is a for loop that goes from 5 down to 1.”
  • “Sam used a for loop with $day += 7 to visit each week of the month.”

Level: Apprentice · More PowerShell terms at this level

Updated

In other subjects