Java Reference
In-Depth Information
Figure 3.6
Output of the BreakDemo program.
The continue Keyword
The continue keyword can be used in any of the loop control structures. It causes
the loop to immediately jump to the next iteration of the loop.
In a for loop, the continue keyword causes flow of control to immedi-
ately jump to the update statement.
■■
In a while loop or do/while loop, flow of control immediately jumps
to the Boolean expression.
■■
The following ContinueDemo program demonstrates how the continue
keyword works. Study the program carefully and try to determine what the
output is.
public class ContinueDemo
{
public static void main(String [] args)
{
System.out.println(“The for loop”);
for(int i = 10; i > 0; i--)
{
if(i % 2 == 0)
{
continue;
}
System.out.println(i);
}
System.out.println(“The while loop”);
int j = 20;
do
{
if(j % 3 != 0)
{
Search WWH ::




Custom Search