PowerShell Continue statement example

Source: Internet
Author: User

PowerShell Continue statement example

This article describes how to use the PowerShell Continue statement. This article provides the sample code directly. For more information, see

When you use the "Continue" statement in a loop, you can skip the current iteration of the loop and Continue to execute the next iteration. If the "Break" statement is used, all the remaining iteration cycles are skipped.

This raises a problem: in a multi-layer nested loop, which loop will be affected. By default, "Continue" only affects the inner loop, but you can also use "Continue" and "Break" to point to a tag of 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 + = 100)

{

"Frequency $ x Hz"

[Console]: Beep ($ x, 500)

Continue outer

Write-Host 'you and I will never meet again unless you change the code'

}

}

Because the continue statement in the above example is adjusted to the outer loop, we will see 10 output of HZ. If the continue statement is deleted, the number of loops increases significantly, the write-host statement will not be skipped.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.