-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContinue_Break.java
More file actions
28 lines (24 loc) · 884 Bytes
/
Continue_Break.java
File metadata and controls
28 lines (24 loc) · 884 Bytes
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
import java.util.*;
public class Continue_Break {
public static void main(String[] args) {
// ? Create object of the scanner class
Scanner sc = new Scanner(System.in);
// * Break and Continue using for loop
for (int i = 1; i <= 5; i++) {
System.out.println(i);
if (i == 3) { // ? If this condition will match then this will break loop from this
System.out.println("Break Loop from this!");
break;
}
}
for (int i = 1; i <= 5; i++) {
System.out.println(i);
if (i == 3) {
System.out.println("Break Loop from this!");
continue; // ? But if we use "continue" instead of "break", it will skip current iteration
}
System.out.println("Out of loop");
}
sc.close();
}
}