About Lesson
Various forms of For Loop
Way 1 : Missing Increment/Decrement Statement
for(i=0;i<5;)
{
statement1;
statement2;
statement3;
i++;
}
however we have to explicitly alter the value i in the loop body.
Way 2 : Missing Initialization in For Loop
i = 0;
for(;i<5;i++)
{
statement1;
statement2;
statement3;
}
we have to set value of ‗i‘ before entering in the loop otherwise it will take garbage value of ‗i‘
Way 3 : Infinite For Loop
i = 0;
for(;;)
{
statement1;
statement2;
statement3;
if(breaking condition)
break;
i++;
}
Infinite for loop must have breaking condition in order to break for loop. otherwise it will cause overflow of stack.