For Loop:
The most common used loop in every programming language.
It's easy and straight.
the
Syntax of The loop is as follows
for ( init-expression ;
cond-expression ; loop-expression)
for example
for (int i = 0 ; i<=10; i++)
{
Code Block
}
in this loop
i = 0; is init-expression
i<=10; is cond-expression
and
i++ is loop-expression
Detail:
i=0; or init-expression:
i=0; or init-expression tells for loop where to start, in this case the initial value of i is 0
i<=10 or Cond-Expression:
i<=10 or Cond-Expression tells the compiler that the maximum lift of Loop is 10 if i goes to the value of 10 you should stoop executing the loop.
i++ or Loop expression:
i++ or Loop expression tells compiler that how much increment you made in every cycle, in this case value of i is increasing by one each time until
its reaches to 10.
No comments:
Post a Comment