Loops/Break: Difference between revisions

2,804 bytes added ,  2 months ago
No edit summary
 
(9 intermediate revisions by 7 users not shown)
Line 384:
=={{header|Amazing Hopper}}==
<p>Flavour "Jambo"</p>
<syntaxhighlight lang="amazing hopperc">
#include <jambo.h>
 
Line 395:
End
 
.</syntaxhighlight>
<p>Assembler Hopper version of this program:</p>
<syntaxhighlight lang="amazing hopper">
main:
____CODE_JUMP____997416047:,
;{20};rand;int;show;eqto(10);jt(____CODE_JUMP____803885359)
 
{"--"};{20};rand;int;{"\n"}print;
,jmp(____CODE_JUMP____997416047),____CODE_JUMP____803885359:,
{"\nEnd of Loop\n"};print;
emptystack?do{{0}};return
</syntaxhighlight>
{{out}}
Line 786 ⟶ 797:
print
end</syntaxhighlight>
 
==={{header|bootBASIC}}===
In bootBASIC, the rnd statement returns an unsigned integer between 0 and 255. 255 divided by 19 gives us 13 without the fraction part, so 13 is the number to divide the random number by to get a range of 0 to 19. All division is integer division.
<syntaxhighlight lang="BASIC">
10 a=rnd/13
20 print a ;
30 if a-10 goto 50
40 goto 100
50 a=rnd/13
55 print random", 20";
60 print a
70 goto 10
100 print
</syntaxhighlight>
{{out}}
<pre>
13, 19
11, 14
18, 4
17, 0
12, 15
0, 13
7, 19
2, 7
1, 3
6, 18
13, 6
9, 10
4, 7
15, 7
10
</pre>
 
==={{header|Commodore BASIC}}===
Line 834 ⟶ 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,296 ⟶ 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 random 20
print randint 20
.</syntaxhighlight>
.
</syntaxhighlight>
 
=={{header|Eiffel}}==
Line 2,237 ⟶ 2,290:
write .i, " "
if .i == 10 { writeln(); break }
write random(0..19), " "
}</syntaxhighlight>
 
Line 2,611 ⟶ 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,195 ⟶ 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,204 ⟶ 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,837 ⟶ 3,908:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
 
var r = Random.new()
885

edits