for loop structure

the general syntax of for loop:

for(initialization; conditionCheck; operation)

{ body }

For loop working can be described in the following steps:

1> Here at first in the for loop the initialization takes place, for example <i = 0>

2> the condition check occurs, for examle < i<5 >

3> the body of the for loop is executed if the condition check is true, else the control gets out of the for loop 

4> operation takes place if the, for example <i++>

5> repeat from step 2.

for loop structure

for(statement; condition; statement)

In for loop any number of statements(in respective postions 1, 3) or conditions can be there, for multiple statements the statements are seperated by <,> and for multiple the conditions are seperated by <&> or, <||>

for example,

for ( statement, statement; condition && condition; statement, statement)

InCode:

for(i=0, j=5; i<5 && j>0; i++, j--)

{

printf("repeated\n");

}

output:

repeated

repeated

repeated

repeated

repeated

Contributor's Info

Created:
0Comment