Loops/Nested: Difference between revisions

no edit summary
(Applesoft BASIC)
No edit summary
Line 3,550:
end;
end;</lang>
 
=={{header|S-BASIC}}==
S-BASIC doesn't have a BREAK or EXIT statement for early termination of a loop, so the most straight-forward approach is to jump out using a GOTO. But since S-BASIC doesn't allow GOTOs from a FOR..NEXT loop, we have to use WHILE..DO instead.
<lang BASIC>
$constant ROWS = 10
$constant COLUMNS = 10
$constant MAXVAL = 20
 
var i, j = integer
dim integer table(ROWS, COLUMNS)
 
rem - populate table using 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 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.
end
 
0done if i > ROWS then print "Sentinal not found!"
 
end
</lang>
{{out}}
<pre>
1 2 7 20
</pre>
 
 
=={{header|Scala}}==
211

edits