1. Single-layer Loop
Using system;
namespace consoleapplication7
{< br> ///
// class1 abstract description.
///
class class1
{< br> ///
// application Program .
//
[stathread]
static void main (string [] ARGs)
{< br> //
// todo: add Code here to start the application
//
for (INT I = 0; I <10; I ++)
{< br> if (I = 7) continue;
// After continue, skip other statements in this loop, continue the next cycle
// if (I = 7) break;
// The statement after the break jumps out of the entire loop and continues to execute the loop
// if (I = 7) return;
// ruturn jumps out of the entire program and returns directly
console. writeline (I);
}< br> console. writeline ("this is the end. ");
}< BR >}
If (I = 7) continue; running result:
0
1
2
3
4
5
6
8
9
This is the end.
If (I = 7) break; running result:
0
1
2
3
4
5
6
This is the end.
If (I = 7) return; running result:
0
1
2
3
4
5
6
2. Nested loop
Using system;
Namespace consoleapplication7
{
/// <Summary>
/// Summary of class1.
/// </Summary>
Class class1
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[Stathread]
Static void main (string [] ARGs)
{
//
// Todo: Add code here to start the application
//
For (INT I = 0; I <10; I ++)
{
For (Int J = 0; j <10; j ++)
{
// If (I = 7) continue;
// If (I = 7) break;
If (I = 7) return;
// If (j = 7) continue;
// If (j = 7) break;
// If (j = 7) return;
Console. Write (I );
Console. Write (j );
}
Console. writeline ();
}
Console. writeline ("this is the end .");
}
}
}
If (I = 7) continue;
If (I = 7) break;
The execution results of the preceding two statements are the same, and the line starting with 7 is empty. It indicates that the break statement can only jump out of one loop.
If (I = 7) return;
Output 7 rows starting with 0 to 6. After the program is executed, all subsequent statements are skipped.
If (j = 7) continue;
A column whose J is 7 is missing
If (j = 7) break;
The output of each column is only 6 to J. It indicates that the break statement can only jump out of one loop.
If (j = 7) return;
Some programs starting with 0 and ending with "06" are output, and all subsequent statements are skipped.