Use of the continue statement in C #

Source: Internet
Author: User

The continue statement forcibly controls the transfer to the minimum closed, or while loop control expression. Pass control to the next iteration of the closed iteration statement where it is located. The continue statement is similar to the break statement. The difference is that it is not to exit a loop, but to start a new iteration of the loop.

The continue statement can only be used in the loop body of the while statement, do/while statement, for statement, and if statement. It may cause errors when used elsewhere! In other words, the continue statement skips the remaining part of the loop body and continues to execute the next loop.

Example:

1. for (var I = 1; I <= 10; I ++)

{

If (I = 6) continue;

Document. write (I );

}

// Output result: 1234578910

2. In this example, the counter is initially counted from 1 to 10, but by using the continue statement with the expression (I <9, the statement between the end of the continue and the for loop body is skipped.

Using System;

Class ContinueTest

{

Static void Main ()

{

For (int I = 1; I <= 10; I ++)

{

If (I <9)

{

Continue;

}

Console. WriteLine (I );

}

}

}

Output:

9

10

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.