Loops/Break: Difference between revisions

 
(5 intermediate revisions by 5 users not shown)
Line 877:
 
 
==={{header|uBasic/4tH}}===
In uBasic/4tH '''UNTIL''' ''<cond>'' is equivalent to '''IF''' ''<cond>'' '''THEN BREAK'''. You can add as many '''UNTIL''' and '''WHILE''' as required in '''FOR..NEXT''' or '''DO..LOOP''' loops.
.</syntaxhighlight lang="qbasic">Do
an = random Rnd(20)
Print n
Until n=10
Print Rnd(20)
Loop</syntaxhighlight>
==={{header|ZX Spectrum Basic}}===
On the ZX Spectrum, for loops must be terminated through the NEXT statement, otherwise a memory leak will occur. To terminate a loop prematurely, set the loop counter to the last iterative value and jump to the NEXT statement:
Line 1,339 ⟶ 1,347:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">repeat
repeat
a = random 20
a = randint 20
print a
until print a = 10
until a = 10
print randomrandint 20
.</syntaxhighlight>
.
</syntaxhighlight>
 
=={{header|Eiffel}}==
Line 2,280 ⟶ 2,290:
write .i, " "
if .i == 10 { writeln(); break }
write random(0..19), " "
}</syntaxhighlight>
 
Line 2,654 ⟶ 2,663:
40 PRINT RND(20)
50 GOTO 10</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
while true {
let a = random int 0..19
print $a
if $a == 10 {break}
print (random int 0..19)
}
</syntaxhighlight>
 
=={{header|Oberon-2}}==
Line 3,238 ⟶ 3,257:
 
=={{header|RPL}}==
RPL does not have any <code>BREAK</code> command. Flags are of great help to exit loops:
≪ 1 CF
'''WHILE''' 1 FC? '''REPEAT'''
RAND 20 * IP
Line 3,247 ⟶ 3,266:
2 DISP '''END'''
'''END'''
The error handling mechanism provides another way to break a loop:
≪ '''IFERR'''
'''WHILE''' 1 '''REPEAT'''
RAND 20 * IP DUP 1 DISP
'''IF''' 10 == '''THEN''' 0 DUP / '''END'''
RAND 20 * IP 2 DISP
'''END'''
'''THEN''' DROP2 '''END'''
 
Line 3,880 ⟶ 3,908:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
 
var r = Random.new()
890

edits