Using the For Statement

Similar to the ForEach-Object cmdlet, the for statement is used to control execution of a script block as long as a condition is true. Most of the time, you will use the for statement to perform an action a certain number of times. In the line of code that follows, notice the basic for construction. Use parentheses to separate the expression being evaluated from the code block contained in curly brackets. The evaluated expression is composed of three sections. The first section is a variable $a; you assign the value of 1 to it. The second section contains the condition to be evaluated. In the code shown here, as long as the variable $a is less than or equal to the number 3, the command in the code block section continues ...

Get Windows PowerShell™ Scripting Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.