The continue statement

The continue statement passes the control to the beginning of the loop. Thus when a continue is encountered in a loop, the following statements inside the body of the loop are skipped and control is transferred to the beginning of the loop for the next iteration.
Thus, the difference between the break and the continue is that break cause the loop to be terminated whereas continue causes the following statement to be skipped and continue with the next iteration.
The use of continue in loops is illustrated below:
in while
while(test condition)
{
------
-----
if(condition)
continue;
------
------
}

in the do-while
do
{
-----
-----
if(condition)
continue;
------
------
}while(test condition)

in the for loop
for(initialization;test condition;increment)
{
_______
_______
if(condition)
continue;
______
______
}

No comments:

Post a Comment