-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestProgram.js
More file actions
73 lines (63 loc) · 1.24 KB
/
Copy pathtestProgram.js
File metadata and controls
73 lines (63 loc) · 1.24 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
// Calculating factorial
let input, output, i
input = 10
output = 1
i = input
while (i > 0) {
output = output * i
i = i - 1
}
console.log('the factorial of', input, 'is', output)
if (output > 100) {
console.log('the factorial is greater than 100')
} else {
difference = 100 - output
console.log('the factorial is', difference, ' less than 100')
}
// Dead code scenario
i = 23 // a dead assignment
i = 34
console.log('i is now equal to', i)
// Try/catch/finally
try {
// assuming any statement here <may> throw an exception, but throw statements <must>
i = 12
i = 13
throw "Oh no!"
i = 14
} catch {
console.log("Oh no!")
} finally {
console.log('Finally!')
}
// Try/catch without finally
try {
// assuming any statement here <may> throw an exception, but throw statements <must>
i = 12
i = 13/0
i = 1923
i = 14
} catch {
console.log("No finally!")
}
// Break/continue
while (i > 0) {
output = output * i
i = i - 1
if (i > 0) {
i=1
break
i=2
}
if (i > 0) {
i=2
} else {
i=1
continue
i=2
}
console.log('i is now equal to', i)
// limitation: get(Final/Initial)Location fails when the last statement in a
// block is an if or some other compound statement
}
console.log('Whew!')