-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreakcontinue.java
More file actions
48 lines (41 loc) · 1.16 KB
/
breakcontinue.java
File metadata and controls
48 lines (41 loc) · 1.16 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class breakcontinue {
public static void main(String[] args) {
System.out.println("brief introduction into break continue");
//Break
for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
System.out.println(i);
//This statement tells the program to stop once the i is equal to 4
}
for (int a = 0; a < 10; a++) {
if (a == 4) {
continue;
}
System.out.println(a);
//this statement tells the program to skip the number 4
}
//Break and continue in while loop
//Break example
int b = 0;
while (b < 10) {
System.out.println(b);
b++;
if (b == 4) {
break;
}
//this breaks the loop once i=4
//while continue example
int c = 0;
while (c < 10) {
if (c == 4) {
c++;
continue;
}
System.out.println(c);
c++;//same as te continue example
}
}
}
}