This article mainly introduced the PowerShell continue statement use example, this article directly to produce the example code, needs the friend may refer to under
When you use the "Continue" statement inside a loop, you can skip the current iteration of the loop and continue with the next iteration. If you use the break statement, all remaining iteration loops are skipped.
This raises the question of which loops are affected in a multi-tiered nested loop. By default, "Continue" only affects the inner loop, but you can also use "Continue" and "break" to point to a label on the outer loop.
?
1 2 3 4 5 6 7 8 9 10 11 |
: Outer Foreach ($element in (1..10)) {for ($x = 1000; $x-lt 1500; $x + +) {"Frequency $x Hz" [Console]::beep ($x, 500 Continue outer write-host ' you and I won't meet again unless you change the code '}} |
Because the continue statement in the example above will be tuned to the outer loop, we will see 10 1000Hz of output, and if the continue statement is deleted, the number of loops will obviously increase and the write-host statement will not skip.