Definition of Repetition
Repetition means One or more instruction repeated for certain amount of time. Number of repetition can be predefined (hard-coded in program) or defined later at run time
There are 3 sets of repetition in programming : For, While, & Do While.
Repetition using For
There are two types of loops for… well… For
Infinite Loop
Loop with no stop condition can use “for-loop” by removing all parameters (exp1, exp2, exp3). To end the loop use break.
Nested Loop
Loop in a loop. The repetition operation will start from the inner side loop.
Repetition using While
The repetition statement provides the ability to execute a statement sequence repeatedly, either for a counted number of times (using the for…to clauses) or until a condition is satisfied (using the while clause). Both forms of clauses can be present simultaneously.
In while operation, statement block of statements may never be executed at all if exp value is false
Repetition using Do-While
In do-while on the other hand statement block of statements will be executed min once. It’s basically while with some modifications.