-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF029_BreakAndContinue.java
More file actions
50 lines (36 loc) · 1.4 KB
/
F029_BreakAndContinue.java
File metadata and controls
50 lines (36 loc) · 1.4 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
49
50
/* Break and Continue / Прерывание и переход к следующей итерации цикла
break и continue можно использовать в циклах.
break - прерывание цикла
continue - переход к следующей итерации цикла
pass - ничего не делает
Пример:
while (условие) {
// do something
if (условие) {
// do something
continue; // переход к следующей итерации цикла
}
if (условие) {
break; // прерывание цикла
}
if (условие) {
pass; // ничего не делает
}
}
*/
import java.util.Scanner;
public class F029_BreakAndContinue {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = "";
while (true) {
System.out.print("Enter something or 'stop' or 'password': ");
input = scanner.next().toLowerCase();
if (input.equals("password"))
continue; // переход к следующей итерации цикла, но не выхода из цикла
if (input.equals("stop"))
break; // выход из цикла while (прерывание цикла)
System.out.println("You entered: " + input);
}
}
}