-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreakContinue.java
More file actions
40 lines (35 loc) · 1.07 KB
/
BreakContinue.java
File metadata and controls
40 lines (35 loc) · 1.07 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
public class BreakContinue {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if (i == 4) {
break; // here will be jump out of the loop
}
System.out.println(i); // output = 0, 1, 2, 3
}
//Now i is one kind of local variable
for (int i = 0; i < 10; i++) {
if (i == 4) {
continue; // Here break the one iteration (in the loop), and the specify statement occurs with condition
}
System.out.println(i); // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}
// break, continue in while loop
int i = 0;
while (i < 10) {
System.out.println(i); // 0, 1, 2, 3
i++;
if (i == 4) {
break;
}
}
// now here i = 4
while (i < 10) {
if (i == 4) {
i++;
continue;
}
System.out.println(i); // 5, 6, 7, 8, 9
i++;
}
}
}