3.2.2 for

Previous Index Next


The for statement is used to loop a set number of times. The basic syntax takes the for of:
for ( InitLoop;  EndLoopCondition; IncrementLoopStatement )
     StatementToExecute
For example:
int loop; //declare integer loop
int y=0;  //declare integer y initialized to 0

for (loop=0; loop < 10; loop++)  //increment loop from 0 to 9
   y= y+ loop*2;                 // set y equal to y plus loop times 2

1