Loops (aka "iterations")

In C++ we have 3 basic kinds of loops:

Pseudocode:
Mom says you have to eat all your peas before you get dessert.

//while loop while (peas are still on the plate) eat peas; //do..while loop do eat peas; while (peas are still on the plate); //for loop, 3 more big bites! for(3 bites) eat peas; ////////////////////////////////// #include <iostream.h> void main() { int x=0; //counter variable do { x=x+2; //increment x cout<<x<<endl; } while (x<10); } /////////////////////////////////// #include <iostream.h> void main() { int x=1;//counter variable while (x!=10)//conditional expression { x=x+2; //increment x cout<<x<<endl; }//compound statement } ///////////////////////////////////// #include <iostream.h> int main() { //counter is the "for loop control variable" and starts at 1 //counter<=3 is the condition under which the loop continues //counter++ is done at the end of each iteration for (int counter=1;counter<=3;counter++) cout<<"GMU totally rules!"<<endl; return 0; } Note that in the example above, only one statement belongs to the loop. If you wish to repeat more than one statement, the statements must be bounded by brackets { }. This is called making a compound statement.