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