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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access