-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLabelled_Continue.java
More file actions
33 lines (28 loc) · 1.23 KB
/
Labelled_Continue.java
File metadata and controls
33 lines (28 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Program: Labelled Continue Demo
* Description: A Java program to demonstrate the usage of a labelled 'continue' statement
* to skip iterations of an outer loop from within an inner loop.
* Author: Amey Thakur
* Reference: https://github.com/Amey-Thakur/OOPM-JAVA-LAB
*/
public class Labelled_Continue {
public static void main(String args[]) {
System.out.println("---------------------------------------------");
System.out.println(" Labelled Continue Demo");
System.out.println("---------------------------------------------");
// Label for the outer loop
outerLoop:
for (int j = 0; j < 5; j++) {
System.out.println("\nOuter Loop: " + j);
for (int i = 0; i < 3; i++) {
// If j is 2, skip the rest of this outer iteration and continue to next outer iteration
if (j == 2) {
System.out.println(" [Condition j==2 met] Skipping to next Outer Loop iteration...");
continue outerLoop;
}
System.out.println(" Inner Loop: " + i);
}
}
System.out.println("---------------------------------------------");
}
}