-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinue_valid.lua
72 lines (61 loc) · 1.17 KB
/
continue_valid.lua
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
-- test the continue statement
-- vim:sw=4:sts=4
-- simple
sum = 0
for i = 1, 10 do
if i == 5 then continue end
sum = sum + i
end
assert(sum == 50)
-- multiple continues
sum = 0
for i = 1, 10 do
if i == 2 then continue end
if i == 5 then continue end
if i == 10 then continue end
sum = sum + i
end
assert(sum == 38)
-- continues and breaks mixed
sum = 0
for i = 1, 10 do
if i == 1 then continue end
if i == 5 then continue end
if i == 8 then break end
sum = sum + i
end
assert(sum == 22)
-- continue in a repeat statement
i = 0
sum = 0
repeat
i = i + 1
if i == 5 then continue end
if i == 8 then continue end
if i == 10 then continue end
sum = sum + i
until i == 10
assert(sum == 55-5-8-10)
-- continue in a while statement
i = 0
sum = 0
while i < 10 do
i = i + 1
if i == 5 then continue end
if i == 10 then continue end
sum = sum + i
end
assert(sum == 55-5-10)
-- nested loops
sum = 0
for i = 1, 10 do
if i == 2 then continue end
if i == 7 then continue end
for j = 1, 4 do
if j == 2 then continue end
if j == 3 then continue end
sum = sum + i + j
end
end
assert(sum == 132)
print("PASSED")