-
Notifications
You must be signed in to change notification settings - Fork 378
/
14-loops.js
80 lines (59 loc) · 1.16 KB
/
14-loops.js
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
/*
Clase 4 en vídeo | 31/07/2024
Mapas, bucles y funciones
https://www.youtube.com/live/xg1GeHKiNzU?si=oiWHK8bDTZ1c98hF&t=885
*/
// Loops o bucles
// for
for (let i = 0; i < 5; i++) {
console.log(`Hola ${i}`)
}
const numbers = [1, 2, 3, 4, 5, 6, 7, 8]
for (let i = 0; i < numbers.length; i++) {
console.log(`Elemento: ${numbers[i]}`)
}
// while
let i = 0
while (i < 5) {
console.log(`Hola ${i}`)
i++
}
// Bucle infinito
// while(true) {
// }
// do while
i = 6
do {
console.log(`Hola ${i}`)
i++
} while (i < 5)
// for of
myArray = [1, 2, 3, 4]
mySet = new Set(["Brais", "Moure", "mouredev", 37, true, "[email protected]"])
myMap = new Map([
["name", "Brais"],
["email", "[email protected]"],
["age", 37]
])
myString = "¡Hola, JavaScript!"
for (let value of myArray) {
console.log(value)
}
for (let value of mySet) {
console.log(value)
}
for (let value of myMap) {
console.log(value)
}
for (let value of myString) {
console.log(value)
}
// break y continue
for (let i = 0; i < 10; i++) {
if (i == 5) {
continue
} else if (i == 7) {
break
}
console.log(`Hola ${i}`)
}