Skip statement
Since break, continue, and goto statements help to jump to a specific statement in the code, they are skip statements. The following describes the three statements.
① Break statement
This statement is often used together with the switch statement. However, C # allows you to use it to jump out of the current statement block. We often use the break statement to jump out of a loop statement block.
The following is an application example of the break statement:
Int I = 0;
While (I <6)
{
Response. Write ("the current I value is" I. tostring (). Trim () "<br>");
If (I = 5)
{
Break; // jump out of the loop when I = 5;
}
I;
}
② Continue statement
This statement controls the Boolean expression returned to the control loop statement.
The following is an application example of the continue statement:
For (INT I = 1; I <= 6; I ++)
{
If (I <5)
{
Continue; // continue execution if I is less than 5
}
Response. Write ("the current I value is" I. tostring (). Trim () "<br>");
}
③ GOTO statement
This statement gives unconditional control to a markup statement. In C #, any statement can be marked. The statement is followed by a colon, a tag identifier, and then a goto keyword. The GOTO statement gives control to the statement named by the tag identifier.
If the GOTO statement is used excessively, the written code may be difficult to read and understand. Generally, it is better to rewrite the code to avoid using the GOTO statement.
The following is an application example of the GOTO statement:
Int I = 0;
While (I <6)
{
Response. Write ("the current I value is" I. tostring (). Trim () "<br>");
If (I = 5)
Goto complete; // If I is equal to 5, the while statement is directly ended at the complete mark;
I;
}
Complete:
Response. Write ("the program jumps directly here to end! ");
Reproduced, Original Source: http://www.amhl.net/wenzhang/DianNao-BianChengKaiFa/20101201/117767.html
Roles of break, continue, and goto