Computer Applications
Distinguish between the following:
continue statement and labelled continue statement
Answer
continue statement | labelled continue statement |
---|---|
continue statement is used to skip the current iteration of a loop and move on to the next iteration. | A labelled continue statement skips the current iteration of an outer loop by using a label before the loop and including the same label in continue statement. |
Syntax:continue; | Syntax:continue <label>; |
For example, for (int i = 0; i <= 3; i++) { System.out.println("i =" + i); for(int j = 0; j < 3; j++) { if (i == 2) { continue; } System.out.print("j = " + j + " "); } System.out.println(); } | For example, outerLoop: for (int i = 0; i <= 3; i++) { for(int j = 0; j < 3; j++) { if (i == 2) { continue outerLoop; System.out.println("i =" + i +" ; j =" + j); } } } |
Related Questions
Write a program in Java to display the following patterns.
1 2 3 4 5 2 3 4 5 3 4 5 4 5 5 4 5 3 4 5 2 3 4 5 1 2 3 4 5
Distinguish between the following:
break statement and labelled break statement
What will be the value of sum after each of the following nested loops is executed?
int sum = 0; for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) sum = sum + (i + j);
What will be the value of sum after each of the following nested loops is executed?
int sum = 0; for (int i = 0; i <= 10; i++) for (int j = 0; j <= 10; j++) sum += i;