Infinite for loop:
An infinite for loop is the one which goes on repeatedly for infinite times. This can happen in two cases:
1) When the loop has no expressions.
for(;;)
{
printf("Welcome2Protec");
}
The above code runs infinite times because there is no test expression to terminate the loop. Hence, Welcome2Protec gets printed infinite times.
2) When the test condition never becomes false.
for(i=1;i<=5;)
{
printf("Welcome2Protec");
}
In the above case, the statement Welcom2Protec gets printed infinite times because the test condition never becomes false. The value of i remains the same because it is never updated and thus the value of i remains smaller than 5 for each iteration.
Empty for loop
An empty for loop is the one which has got no body. In simple words, it contains no statements or expressions in its body. It can be used for time-consuming purposes. Each iteration takes its own time for compilation and execution. Usually, it is too small to be of any significant importance. Here’s the syntax of an empty for loop:
for(i=1;i<=5;i++)
{}
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.