File: testsuite_loop_include.kbs

package info (click to toggle)
basic256 2.0.99.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,888 kB
  • sloc: cpp: 17,185; yacc: 4,025; lex: 1,466; java: 1,091; sh: 39; xml: 33; makefile: 20
file content (246 lines) | stat: -rw-r--r-- 6,143 bytes parent folder | download | duplicates (2)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# testsuite_loop_include section for BASIC256

# Modification History
# date		programmer	description
# 20140204	j.m.reneau	added crazy if structures when if/then/else
#                       moved to a statement and not a stand alone line (1010002)
# 20160329	j.m.reneau	added second test if exit for to test condition fixed 1.99.99.21
# 20160611  j.m.reneau	added cases for the for statement to match
#						the FOR behaviour of most other BASICs 1.99.99.40
# 20200420  j.m.reneu   added foreach tests (2.0.0.0)

currentsuite = "loop"

#test for
total = 0
for t = 1 to 100
   if t = 3 or t = 4 or t = 10 then
      print "continue for = skip " + t;
      continuefor
   end if
   total = total + t
   print t + " " + total;
   if total > 100 then
      print "exit for";
      exit for
   end if
next t
print
call n("FOR - Exit and Continue", total, 103)

total = 0
for x = 0 to 7
for y = 0 to 5
if y > 3 then  exit for
next y
total = total + x
next x
call n("FOR - Exit outside still run", total, 28)


#test for compound
total = 0:for t = 1 to 100:if t = 3 or t = 4 or t = 10 then print "continue for = skip " + t;: continuefor
total = total + t:print t + " " + total:if total > 100 then print "exit for";: exit for
next t: print:call n("FOR compound - Exit and Continue", total, 103)

# normal 1..10 - loop 10 times
n = 0
for t = 1 to 10 step 1
	print " "+t
	n = n + t
next t
call n("FOR normal 1..10 - loop 10 times", n, 55)

# forwards with a backwards step - loop ZERO times
n = 0
for t = 1 to 10 step -1
	print " "+t
	n = n + t
next t
call n("FOR forwards with a backwards step - loop ZERO times", n, 0)


# backwards 10 to 1 - loop 10 times
n = 0
for t = 10 to 1 step -1
	print " "+t
	n = n + t
next t
call n("FOR backwards 10 to 1 - loop 10 times", n, 55)


# backwards with a forwards step - loop ZERO times
n = 0
for t = 10 to 1 step 1
	print " "+t
	n = n + t
next t
call n("FOR backwards with a forwards step - loop ZERO times", n, 0)

# forward - step 0 - loop forever with starting value
n = 0
for t = 1 to 10 step 0
	print " "+t
	n = n + t
	if n = 42 then exit for
next t
call n("FOR forward - step 0 - loop forever with starting value", n, 42)

# backward - step 0 - loop forever with starting value
n = 0
for t = 10 to 1 step 0
	print " "+t
	n = n + t
	if n = 420 then exit for
next t
call n("FOR backward - step 0 - loop forever with starting value", n, 420)

# same start and end forward step - loop once
n = 0
for t = 10 to 10 step 1
	print " "+t
	n = n + t
next t
call n("FOR same start and end forward step - loop once", n, 10)

# same start and end backward step - loop once
n = 0
for t = 10 to 10 step -1
	print " "+t
	n = n + t
next t
call n("FOR same start and end backward step - loop once", n, 10)

# normal .5 to 2 step .5 - loop 10 times
n = 0
for t = .5 to 2 step .5
	print " "+t
	n = n + t
next t
call n("FOR float normal .5 to 2 step .5 - loop 10 times", n, 5)

# forwards with a backwards step - loop ZERO times
n = 0
for t = .5 to 2 step -.5
	print " "+t
	n = n + t
next t
call n("FOR float forwards with a backwards step - loop ZERO times", n, 0)

# backwards 2 to .5 - loop 10 times
n = 0
for t = 2 to .5 step -.5
	print " "+t
	n = n + t
next t
call n("FOR float backwards 2 to .5 - loop 10 times", n, 5)

# backwards with a forwards step - loop ZERO times
n = 0
for t = 2 to .5 step .5
	print " "+t
	n = n + t
next t
call n("FOR float backwards with a forwards step - loop ZERO times", n, 0)

# forward - step 0 - loop forever with starting value
n = 0
for t = .5 to 2 step 0
	print " "+t
	n = n + t
	if n = 10 then exit for
next t
call n("FOR float forward - step 0 - loop forever with starting value", n, 10)

# backward - step 0 - loop forever with starting value
n = 0
for t = 2 to .5 step 0
	print " "+t
	n = n + t
	if n = 12 then exit for
next t
call n("FOR float backward - step 0 - loop forever with starting value", n, 12)

# same start and end forward step - loop once
n = 0
for t = .5 to .5 step .5
	print " "+t
	n = n + t
next t
call n("FOR float same start and end forward step - loop once", n, .5)

# same start and end backward step - loop once
n = 0
for t = 2 to 2 step -.5
	print " "+t
	n = n + t
next t
call n("FOR float same start and end backward step - loop once", n, 2)

# test do
total = 0
t = 0
do
   t++
   if t = 3 or t = 4 or t = 10 then
      print "continue do = skip " + t;
      continue do
   end if
   total = total + t
   print t + " " + total
   if total > 100 then
      print "exit do"
      exit do
   end if
until t >= 100
call n("DO - Exit and Continue", total, 103)

# test do compound (single line showing off)
total = 0:t = 0:do:t++:if t = 3 or t = 4 or t = 10 then :print "continue do = skip " + t:continue do: endif: total = total + t:print t + " " + total:if total > 100 then : print "exit do": exit do: endif: until t >= 100:call n("DO compound - Exit and Continue", total, 103)

# test while
total = 0
t = 0
while true
   t++
   if t = 3 or t = 4 or t = 10 then
      print "continue while = skip " + t
      continue while
   end if
   total = total + t
   print t + " " + total
   if total > 100 then
      print "exit while"
      exit while
   end if
end while
call n("WHILE - Exit and Continue", total, 103)

# test while comound
total = 0:t = 0:while true:t++:if t = 3 or t = 4 or t = 10 then:print "continue while = skip " + t:continue while:end if:total = total + t:print t + " " + total:if total > 100 then:print "exit while":exit while:end if:end while:call n("WHILE compound - Exit and Continue", total, 103)


#test foreach with numbers
total = 0
foreach a in {3,5,7,9}
	total = total / 2 + a
next a
call n("For Each - List of Numbers", total, ((3 / 2 + 5)/ 2 + 7)/2 + 9)

total = 0
b = {3,5,7,9}
for each a in b
	total = total / 2 + a
next a
call n("For Each - Array of Numbers", total, ((3 / 2 + 5)/ 2 + 7)/2 + 9)

#test foreach with strings
total = ''
b = {'cow','dog','cat'}
foreach a in b
	total = a + total
next a
call s("For Each - Array of strings", total, 'catdogcow')

# foreach compound
total = 0: foreach a in {3,5,7,9}: total = total / 2 + a: next a: call n("For Each compound - List of Numbers", total, ((3 / 2 + 5)/ 2 + 7)/2 + 9)