forked from mouredev/hello-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoops.java
More file actions
109 lines (83 loc) · 2.38 KB
/
Copy pathLoops.java
File metadata and controls
109 lines (83 loc) · 2.38 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package basic.c06_loops;
/*
Clase 5 - Bucles y funciones (06/05/2025)
Vídeo: https://www.twitch.tv/videos/2452053839
*/
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class Loops {
public static void main(String[] args) {
// Loops
// - for controlado por contador
for (int index = 0; index < 5; index++) {
System.out.println("Hola, Java!");
}
String[] names = {"Brais", "Moure", "mouredev"};
for (int index = 0; index < names.length; index++) {
System.out.println(names[index]);
}
// - for-each
for (String name: names) {
System.out.println(name);
}
HashSet<Integer> numbers = new HashSet<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.add(4);
numbers.add(5);
for (Integer number: numbers) {
System.out.println(number);
}
HashMap<String, String> emails = new HashMap<>();
emails.put("Brais", "brais@gmail.com");
emails.put("Moure", "moure@gmail.com");
emails.put("MoureDev", "mouredev@gmail.com");
for (Map.Entry<String, String> email: emails.entrySet()) {
System.out.println(email.getKey());
System.out.println(email.getValue());
}
// - while
int index = 0;
while (index < 5) {
System.out.println("Hola, Java!");
index++;
}
index = 0;
while (index < names.length) {
System.out.println(names[index]);
index++;
}
index = 0;
boolean find = false;
while (!find) {
System.out.println(names[index]);
if (names[index].equals("Moure")) {
find = true;
}
index++;
}
// - do-while
index = 0;
do {
System.out.println("Hola, Java!");
index++;
} while (index < 0);
// Control de bucles
// - break
for (String name: names) {
if (name.equals("Moure")) {
break;
}
System.out.println(name);
}
// - continue
for (int i = 0; i < 5; i++) {
if (i == 3) {
continue;
}
System.out.println(i);
}
}
}