forked from dmsc/fastbasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestloop.bas
More file actions
100 lines (97 loc) · 1.36 KB
/
Copy pathtestloop.bas
File metadata and controls
100 lines (97 loc) · 1.36 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
? "Test UNTIL"
' Check REPEAT/UNITL
a=0
repeat
a=a+1
? a,
until a>=10
? "="; a
? "Test WHILE"
' Check WHILE/WEND
a=0
while a<10
a=a+1
? a,
wend
? "="; a
? "Test DO/LOOP"
' Check DO/LOOP with EXIT
a=0
do
a=a+1
if a > 10
exit
endif
? a,
loop
? "="; a
? "Test nested loops"
' Check nested loops with multiple EXIT
b=1
repeat
a=1
while a<10
c= a*a+b*b
a=a+1
if c > 50
? 1
exit
endif
if a + b > 10
? 0
exit
endif
? c,
wend
b=b+1
until b>10
? "Test FOR"
for i=10 to 0 : ? i, : next i
? "="; i
if i <> 10 then ? "--- BAD ---"
for i=10 to 0 step -1: ? i, : next i
? "="; i
if i <> -1 then ? "--- BAD ---"
for i=0 to 10 : ? i, : next i
? "="; i
if i <> 11 then ? "--- BAD ---"
for i=0 to 10 step -1: ? i, : next i
? "="; i
if i <> 0 then ? "--- BAD ---"
for i=10 to -10 step 3: ? i, : next i
? "="; i
if i <> 10 then ? "--- BAD ---"
for i=10 to -10 step -3: ? i, : next i
? "="; i
if i <> -11 then ? "--- BAD ---"
for i=-10 to 10 step 3: ? i, : next i
? "="; i
if i <> 11 then ? "--- BAD ---"
for i=-10 to 10 step -3: ? i, : next i
? "="; i
if i <> -10 then ? "--- BAD ---"
? "Test nested FOR"
a = 0
for i=1 to 10
for j=i to 10
? j,
a = a + j
next j
? "="; j
next i
? "="; a
? "Test nested FOR with EXIT"
a = 0 : l = 0
for i=1 to 10
for j=i to 10
? j,
a = a + j
l = l + 1
if l >= 7
l = 0
exit
endif
next j
? "="; l
next i
? "="; a