C has looping , in which a sequence of statements are executed until some conditions for termination of the loop are satisfied.
A program loop therefore consists of two segments, one known as the ‘body of the loop’ and the other known as the ‘control statement’ .The control statement tests certain conditions and then directs the repeated execution of the statements contained in the body of the loop.
Depending on the position of the control of the control statement in the loop, a control structure may be classified either as the ‘entry-controlled loop (top down controlled loop) or as the ‘exit-controlled loop( bottom up controlled loop)’ .The entry controlled and exit controlled loop.
Entry-controlled loops:- while( ) , for () . Exit controlled loop:- do-while(). C has three forms of iteration statement: do statement while( <expression> ) ; while ( <expression> ) <statement> for ( <expression> ; <expression> ; <expression> ) <statement>
In the while and do statements, the substatement is executed repeatedly so long as the value of the expression remains nonzero (true). With while, the test, including all side effects from the expression, occurs before each execution of the statement; with do, the test follows each iteration. Thus, a do statement always executes its sub statement at least once, whereas while may not execute the sub statement at all.
If all three expressions are present in a for, the statement
for (e1; e2; e3) s; is equivalent to e1; while (e2) { s; e3; }
except for the behavior of a continue; statement (which in the for loop jumps to e3 instead of e2).
Any of the three expressions in the for loop may be omitted. A missing second expression makes the while test always nonzero, creating a potentially infinite loop.
Since C99, the first expression may take the form of a declaration, typically including an initializer, such as
for (int i=0; i< limit; i++){ ... }
The declaration’s scope is limited to the extent of the for loop.