Slide 9.6: The switch statement (cont.)
Slide 9.8: Looping (cont.)
Home

Looping


C# provides several kinds of looping.

Do Loop
The formats and examples are
For Loop
The format and an example are
 for ( init; condition; increment ) {
    statement(s);
 }
  ________________________An example________________________
 for ( counter = 1; counter <= 1000; counter += 1 ) {
    acc += counter;
 }

Nested Loops
The nested for loop format is
 for ( init; condition; increment ) {
    for ( init; condition; increment ) {
       statement(s);
    }
    statement(s);
 }
The nested while loop format is
 while ( condition ) {
    while ( condition ) {
       statement(s);
    }
    statement(s);
 }
The nested do ... while loop format is
 do {
    statement(s);
    do {
       statement(s);
    }
    while( condition );
 }
 while( condition );