-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.js
More file actions
32 lines (25 loc) · 870 Bytes
/
loops.js
File metadata and controls
32 lines (25 loc) · 870 Bytes
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
// There are many types of loops
// Essentially they all do the same thing: to excute specific code a certain amount of times
// However, depending on what you're trying to achieve certain loops may be more effective than others
// while loop
// requires you specify a condition/check for a state (i.e. T / F)
// continues to run the code as long as condition/state is true
// while (condition) {}
var bottles = 100
function numBottles() {
while (bottles > 0){
bottles --;
console.log(bottles + " bottles of beer on the wall.")
}
}
numBottles()
// for loop
// requires you to specify how long you want your code to run
// focuses on iteration as opposed to state
// for (start; end; change) {}
function numCans() {
for ( var cans = 100; cans >= 0; cans --) {
console.log(cans + " cans of pop on the wall.")
}
}
numCans()