-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.html
More file actions
52 lines (48 loc) · 1.28 KB
/
loops.html
File metadata and controls
52 lines (48 loc) · 1.28 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Loops</title>
</head>
<body>
<script>
// print the number from 1 to five
var limit = 5;
var counter;
// 1. do something
// 2. another
// ..
// 5. go to 1, if (I have enough money)
// go to
counter = 0; /*Initialization*/
while (counter < limit /*condition*/) { // This may never be executed
counter++; /*increment*/
if( counter === 2){
console.log("found #2, skip it");
continue;
}
console.log("While #" + counter);
} // go to -> condition
// stop
// This is going to be executed at least once
counter = 1; /*Initialization*/
do {
console.log(counter);
counter++;/*increment*/
} while (counter <= limit/*condition*/);
for (
counter = 1; // 1 First time (once)
counter <= limit; // 2. should i continue?
counter++ // 4. increment -> go to condition
) {
// if we find the number 3 everything stops
if(counter === 3){
console.log("found #3, break");
break;
}
// you're repeating an action, but the data is different
console.log("for loop: " + counter); // 3. body
}
</script>
</body>
</html>