|
|
|
the effect is:
|
![]() |
|
the effect is:
|
![]() |
|
public class Continue02 { public static void main(String[] args) { int a; a = 1; while ( a <= 10 ) // Run a = 1, 2, ..., 10 { if ( a == 4 ) { continue; // Skip printing 4... } System.out.println(a); // Print a a++; } } } |
This program contains an infinite loop, because the continue statement will skip over a++.
Result:
|
Since variable a does not change, you have an infinite loop
How to run the program:
|
Output:
1 2 3 (program hangs here forever)...... |
public class Continue03 { public static void main(String[] args) { int a; for ( a = 1; a <= 10 ; a++ ) // Run a = 1, 2, ..., 10 { if ( a == 4 ) { continue; // Skip printing 4... } System.out.println(a); // Print a } } } |
Output of this program:
1 2 3 (skips over 4 !) 5 6 7 8 9 10 |
Reason:
|
How to run the program:
|