C# provides several kinds of looping.
Do Loop
The formats and examples are
do {
statement(s);
} while ( condition );
_____________________An example_____________________
do {
num.Text = counter;
counter = counter + 1;
} while ( counter <= 1000 );
while ( condition ) {
statement(s);
}
_____________________An example_____________________
while ( counter > 1000 ) {
num.Text = counter;
counter = counter + 1;
}
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 );