Sometimes it is useful to force an early iteration of a loop. That
is, you might want to continue running the loop but stop processing the
remainder of the code in its body for this particular iteration.
A goto just past the body of the loop, to the loop’s end. The continue statement performs such an action.
In while and do-while loops, a continue statement causes control to be transferred directly to the conditional expression that controls the loop.
In a for loop, control goes first to the iteration portion of the for statement and then to the conditional expression. For all three loops, any intermediate code is bypassed.
Here is an example program that uses continue statement
A goto just past the body of the loop, to the loop’s end. The continue statement performs such an action.
In while and do-while loops, a continue statement causes control to be transferred directly to the conditional expression that controls the loop.
In a for loop, control goes first to the iteration portion of the for statement and then to the conditional expression. For all three loops, any intermediate code is bypassed.
Here is an example program that uses continue statement
// Demonstrate continue.
class WLContinue
{
public static void main(String args[])
{
for(int i=0; i<5; i++)
{
if (i%2 == 0)
continue;
System.out.println("i: "+i);
}
}
}
Type following command in command prompt
javac WLContinue.java
java WLContinue
i: 1
i: 3
No comments:
Post a Comment
If you have any query please comment here, Will get back to you :)