forked from mouredev/hello-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14-loops.js
More file actions
72 lines (53 loc) · 1.17 KB
/
14-loops.js
File metadata and controls
72 lines (53 loc) · 1.17 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
// Loops o bucles
//For
for (let a=1;a<=5;a++){
console.log(`hola for ${a}`)
}
const numbers=[1,2,3,4,5]
for(let i=0;i<numbers.length;i++){
console.log(`Elemento: ${numbers[i]}`)
}
//while
let i=0
while(i<5){
console.log(`hola while ${i}`)
i++
}
//do while
i=0
do{
console.log(`hola do while ${i}`)
i++
}while(i<5)
// for of sirve para recorrer valores de algo que se iterable
myArray=[1,2,3,4]
myset = new Set (["Oliver","Rustrian","olirustrian",20,true,"algo"])
myMap= new Map([
["Name","Oliver"],
["Apellido","Rustrian"],
])
myString="Hola javascript"
for (let valor of myArray){
console.log(valor)
}
for (let valor of myset){
console.log(valor)
}
for (let valor of myMap){
console.log(valor)
}
for (let valor of myString){
console.log(valor)
}
// Buenas prácticas
//Break y continue
for (let a=1;a<=10;a++){
if (a==5)
{
continue
} else if (a==6){
break
}
console.log(`hola for ${a}`)
}