Program Control: Repetition


Repetition Definition
Repetition means one or more instruction repeated for a certain amount of time. Repetitions can be predefined in the program or can be defined later at run time
examples of repetition/looping operation: for, while, and do-while.
The C programming language still features the old fashioned go to command but is rarely used due to it being used resulting in a messed up code or in other words spaghetti code.

FOR
the for command syntax is
for(initialization; conditional; increment or decrement){
          statement1;
          statement2;

WHILE
the while command syntax is
while (exp){
       statement1;
       statement2;
}
the exp is a boolean expression meaning will only result to true or false. Statement will be executed while exp is true. The exp evaluation is done before the statements executed.

DO-WHILE
the do-while command syntax is
do{
    statements;
} while(exp);
this command will keep executing while exp is true. The exp evaluation is done after executing the statement(s)

BREAK AND CONTINUE
break is used to end a loop operation or to end the switch operation
continue is used to skip a loop statements once and continue to the next loop operation


Comments