-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_ciclos.js
More file actions
95 lines (75 loc) · 1.91 KB
/
Copy path09_ciclos.js
File metadata and controls
95 lines (75 loc) · 1.91 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
// #########
// CICLO FOR
// #########
for (let index = 0; index < 10; index++) {
console.log(index) // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}
// break en ciclos for
for (let index = 0; index < 10; index++) {
console.log(index) // 0, 1, 2, 3, 4, 5
if (index === 5) {
break
}
}
// continue en ciclos for
for (let index = 0; index < 10; index++) {
console.log(index) // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
if (index === 5) {
console.log("llegaste a la mitad") // llegaste a la mitad
continue
}
}
// ###################
// EJERCICIO FIZZ BUZZ
// ###################
// si un numero es multiplo de 3 imprimir fizz
// si un numero es multiplo de 5 imprimir buzz
// si un numero es multiplo de ambon imprimir fizz buzz
for (let index = 0; index < 100; index++) {
if (index % 3 === 0 && index % 5 === 0) {
console.log(index, "-> fizz buzz");
} else {
if (index % 3 === 0) {
console.log(index, "-> fizz");
}
if (index % 5 === 0) {
console.log(index, "-> buzz");
}
}
}
// ###########
// CICLO WHILE
// ###########
let i = 0
while (i <= 10) {
console.log(i) // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
i++
}
// ##############
// CICLO DO WHILE
// ##############
let j = 0
do {
console.log(j) // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
j++
} while (j < 10);
// ##############
// CICLO FOR EACH
// ##############
let numeros = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
numeros.forEach(element => {
console.log(element * 2) // 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
});
// ############
// CICLO FOR IN
// ############
let frutas = ["mango", "fresa", "naranja", "pera"]
//obtener los indices de una lista
for (const key in frutas) {
console.log(key) // '0', '1', '2', '3'
console.log(Number(key)) // 0, 1, 2, 3
}
//obtener los valores de una lista
for (const value of frutas) {
console.log(value) // 'mango', 'fresa', 'naranja', 'pera'
}