-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops_sample.js
More file actions
80 lines (52 loc) · 1.48 KB
/
loops_sample.js
File metadata and controls
80 lines (52 loc) · 1.48 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
console.log('hello');
console.log('hello');
console.log('hello');
console.log('hello');
console.log('hello');
console.log('hello');
console.log('hello');
for(let i = 0; i < 7; i++){
console.log('hello');
};
for ( let i = 0; i < 7; i++ ) {
console.log('hello');
};
let total = 0;
for(let i = 10; i > 0; i--){
total = total + i;
}
console.log(total);
let num = 1;
while (num < 6){
console.log("I'm counting! The number is " + num);
num = num + 1;
}
console.log("We are done. Goodbye world!");
let num = 6;
do {
console.log("I'm counting! The number is " + num);
num = num + 1;
}
while (num < 6);
console.log("We are done. Goodbye world!");
let colors = ['blue', 'green', 'red', 'chartreuse'];
// a simple array of strings
for(let i = 0; i < colors.length; i++){
// by using the length of our colors array, we can make the condition
// of our for loop match the number of elements in the array!
console.log(colors[i]);
// now we can use i to log the elements of the color array induvidually
};
let names = ['Anna', 'Oscar', 'Kadie', 'Steve', 'Elle', 'Boris', 'Lord Humongous'];
for(let i = 0; i < names.length; i++){
if(names[i] === 'Kadie'){
console.log('Kadie is in our array!');
break;
}
}
console.log('We finished looping!');
let names = ['Anna', 'Oscar', 'Kadie', 'Steve', 'Elle', 'Boris', 'Lord Humongous'];
for(let i = 0; i < names.length; i++){
if(names[i] === 'Steve'){ continue };
console.log(names[i]);
};