At times, certain instructions require repeated execution. Loops are an ideal way to do the same. A loop represents a set of instructions that must be repeated. In a loop's context, a repetition is termed as an iteration.
The following figure illustrates the classification of loops-
Definite Loop
A loop whose number of iterations are definite/fixed is termed as definite loop. The 'for loop' is an implementation of a definite loop.
for (initial_count_value;
termination-condition; step) {
//statements
}
Indefinite Loop
An indefinite loop is used when the number of iterations in a loop is indeterminate or unknown.
Indefinite loops can be implemented using:
The Loop Control Statements
Using Labels to control the flow
A Label is simply an identifier followed by a colon(:) that is applied to a statement or a block of code. a label can be used with break and continue to control the flow more precisely.
Line breaks are not allowed between the 'continue' or 'break' statement and its label name. Also, there should not be any statement in between a label name and an associated loop.