forked from ErikNas/aqa-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoops.java
More file actions
executable file
·94 lines (74 loc) · 1.92 KB
/
Copy pathLoops.java
File metadata and controls
executable file
·94 lines (74 loc) · 1.92 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package ru.education.aqajava.theory.base;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
public class Loops {
@Test
void forExample1() {
// int i = i + 1;
for (int i = 0; i < 10; i += 3) {
System.out.println(i);
}
}
@Test
void forExample2() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
System.out.print(i);
System.out.print(j + " ");
}
System.out.println();
}
}
@Test
void forExample3() {
List<String> l = new ArrayList<>();
l.add("Арсений"); // 0
l.add("Данила"); // 1
// List<String> m = List.of("Мясо", "Рис");
// m.add("asd");
// System.out.println(l.get(1));
for (String s : l) {
System.out.println(s);
}
//
// // Вариант через счетчик
for (int i = 0; i < l.size(); i++) {
System.out.println(l.get(i));
}
}
@Test
void whileExample() {
byte i = 0;
while (i < 3) {
System.out.println(i);
i++;
}
}
@Test
void doWhileExample() {
int i = 0;
do {
System.out.println(i);
i++;
} while (i < 3);
}
@Test
void doWhileExample2() {
boolean taskIsDone;
// do {
// taskIsDone = execTaskAndGetStatus();
// System.out.println("loop");
// } while (!taskIsDone);
System.out.println("Task is DONE!");
// Тот же вариант через while
taskIsDone = execTaskAndGetStatus();
while (!taskIsDone) {
taskIsDone = execTaskAndGetStatus();
}
// System.out.println("Task is DONE!");
}
private boolean execTaskAndGetStatus() {
return true;
}
}