Control Sructures - Repetition

Both of the following loops add up all of the numbers between 1 and 50.

// while loop example // loop body runs 50 times, condition checked 51 times int i = 1, sum = 0; while (i cout do/while loop example // loop body runs 50 times, condition checked 50 times int i = 1, sum = 0; do < sum += i; // means: sum = sum + i; i++; // means: i = i + 1; >while (i 

Example Links

The for loop

 for (initialCondition; testExpression; iterativeStatement) statement 
 for (initialCondition; testExpression; iterativeStatement) < statement1; statement2; // . statementN; >