RosettaCodeData/Task/Loops-Nested/S-BASIC/loops-nested-1.basic

41 lines
789 B
Plaintext

$constant ROWS = 10
$constant COLUMNS = 10
$constant MAXVAL = 20
var i, j = integer
dim integer table(ROWS, COLUMNS)
rem - populate table using nested FOR..NEXT loops
for i=1 to ROWS
for j=1 to COLUMNS
table(i, j) = int(rnd(1) * MAXVAL) + 1
next j
next i
rem - show results using nested WHILE..DO loops
i = 1
while i <= ROWS do
begin
j = 1
while j <= COLUMNS do
begin
print using "## "; table(i, j);
if table(i, j) = MAXVAL then goto 0done
j = j + 1
end
print
i = i + 1
end
comment
Although S-BASIC allows alphanumeric line numbers as the target
of a GOTO or GOSUB statement, the first "digit" must in fact be
a number, as shown here.
end
0done if i > ROWS then print "target value"; MAXVAL; " not found!"
end