Category: 4. Continue & Break Statement
-
Break Statement
The Break statement is used in PowerShell to exit the loop immediately. It can also be used to stop the execution of a script when it is used outside the switch or loop statement. Examples Example 1: The following example displays how to use a break statement to exit a ‘for’ loop: Output:1 2 3 4 5 In…
-
Example 3:
The following example uses for loop with continue statement: Output:10 9 8 7 6 4 3 2 1
-
Example 2:
The following example uses a do-while loop with a continue statement which displays the values from 10 to 20, excluding 15 and 18. Output:10 11 12 13 14 16 17 19 20
-
Continue Statement
The Continue statement is used in PowerShell to return the flow of the program to the top of an innermost loop. This statement is controlled by the for, Foreach and while loop. When this statement is executed in a loop, the execution of code inside that loop following the continue statement will be skipped, and the next iteration of a loop…