continue notes:-
o is used to force an early iteration of a loop.
o continues running the loop, but stop processing the remainder of the
code
in its body for this particular iteration just as a goto statement
thats just past the body of the loop, to the loop’s end.
o In while and do-while loops, a continue statement causes control to be
transferred directly to the conditional expression that controls the
loop.
o In a for loop, control goes first to the iteration portion of the for
statement and then to the conditional expression.
o For all three loops, any intermediate code is bypassed.
example1:
// Demonstrate continue.
class Continue {
public static void main(String args[]) {
for(int i=0; i<10; i++) {
System.out.print(i + " ");
if (i%2 == 0) continue;
System.out.println("");
}
}
}
example2:
// Using continue with a label.
class ContinueLabel {
public static void main(String args[]) {
outer: for (int i=0; i<10; i++) {
for(int j=0; j<10; j++) {
if(j > i) {
System.out.println();
continue outer;
}
System.out.print(" " + (i * j));
}
}
System.out.println();
}
}
example3:
o is used to force an early iteration of a loop.
o continues running the loop, but stop processing the remainder of the
code
in its body for this particular iteration just as a goto statement
thats just past the body of the loop, to the loop’s end.
o In while and do-while loops, a continue statement causes control to be
transferred directly to the conditional expression that controls the
loop.
o In a for loop, control goes first to the iteration portion of the for
statement and then to the conditional expression.
o For all three loops, any intermediate code is bypassed.
example1:
// Demonstrate continue.
class Continue {
public static void main(String args[]) {
for(int i=0; i<10; i++) {
System.out.print(i + " ");
if (i%2 == 0) continue;
System.out.println("");
}
}
}
example2:
// Using continue with a label.
class ContinueLabel {
public static void main(String args[]) {
outer: for (int i=0; i<10; i++) {
for(int j=0; j<10; j++) {
if(j > i) {
System.out.println();
continue outer;
}
System.out.print(" " + (i * j));
}
}
System.out.println();
}
}
example3: