Loops/Do-while: Difference between revisions

Content deleted Content added
Fix dead links by using web archive
Bernie (talk | contribs)
m Moved FutureBasic entry out of the BASIC group
 
(13 intermediate revisions by 8 users not shown)
Line 245:
</pre>
 
===AnA alternate ("Gotogoto-less") approach===
{{works with|A60}}
While a judicious "goto" may (oddly enough) actuallysometimes be clearer inthan this particularthe contextalternative, it is possible to avoid it in this case by using the for-while statement and a boolean flag to implement a test-at-the-bottom loop. (Note that though the A60 interpreter permits, it thankfully does not require, the ugly tick marks around reserved words which mar many (but not the Burroughs) ALGOL 60 translators.)
<syntaxhighlight lang="algol60">
begin
Line 255:
i := 0;
another := true;
for i := i + 1 while another do
begin
i := i + 1;
outinteger(1,i);
comment - repeatstop untilonce i mod 6 = 0;
if i = (i div 6) * 6 then another := false;
end;
Line 639 ⟶ 640:
<pre>
1 2 3 4 5 6
</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">window 1
 
dim as long i
 
do
i++
print i
until ( i mod 6 == 0 )
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>
1
2
3
4
5
6
</pre>
 
Line 755 ⟶ 735:
60 END
</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#Minimal BASIC|Minimal BASIC]] solution works without any changes.
 
==={{header|NS-HUBASIC}}===
Line 806 ⟶ 789:
PRINT a;
LOOP WHILE a MOD 6 <> 0</syntaxhighlight>
 
==={{header|Quite BASIC}}===
The [[#Minimal BASIC|Minimal BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
Line 820 ⟶ 806:
30 PRINT X
40 IF X/6<>INT (X/6) THEN GOTO 20</syntaxhighlight>
 
==={{header|SmallBASIC}}===
<syntaxhighlight lang="qbasic">
repeat
v++
print v
until(v mod 6 == 0)
</syntaxhighlight>
 
==={{Header|Tiny BASIC}}===
Line 929 ⟶ 923:
std::cout << val << std::endl;
}while(val % 6 != 0);</syntaxhighlight>
 
=={{header|C3}}==
In this example we use default zero initialization of locals in C3.
<syntaxhighlight lang="c3">int val;
do
{
io::printn(++val);
}
while (val % 6 != 0);</syntaxhighlight>
 
=={{header|Chapel}}==
Line 1,168 ⟶ 1,171:
 
=={{header|EasyLang}}==
<syntaxhighlight lang=text>
EasyLang does not include an built-in do-while loop, but a repeat-until loop can be used, with the condition inside a '''not''' operator.
<syntaxhighlight lang="easylang">
value = 0
repeat
value += 1
print value
until not (value mod 6 <>= 0)
.
</syntaxhighlight>
Line 1,417 ⟶ 1,419:
println[n]
} while n mod 6 != 0</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1
 
dim as long i
 
do
i++
print i
until ( i mod 6 == 0 )
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>
1
2
3
4
5
6
</pre>
 
=={{header|GAP}}==
Line 2,310 ⟶ 2,333:
inc val
echo val</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
mut n = 0
while true {
$n += 1
print $n
if $n mod 6 == 0 {break}
}
</syntaxhighlight>
 
=={{header|Oberon-2}}==
Line 2,452 ⟶ 2,485:
until i mod 6 = 0
end.</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
begin
var a := 0;
repeat
a += 1;
Print(a);
until a mod 6 = 0;
end.
</syntaxhighlight>
 
 
 
=={{header|Perl}}==
Line 2,909 ⟶ 2,955:
end;
end;</syntaxhighlight>
 
=={{header|S-BASIC}}==
S-BASIC's REPEAT..UNTIL control structure is the equivalent of a
DO..WHILE statement with the terminating test inverted.
<syntaxhighlight lang="BASIC">
rem - return n mod m
function mod(n, m = integer) = integer
end = n - (n / m) * m
 
var i = integer
i = 0
repeat
begin
i = i + 1
print i;
end
until mod(i, 6) = 0
 
end
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6
</pre>
 
=={{header|Scala}}==
Line 3,266 ⟶ 3,336:
endmodule
</syntaxhighlight>
 
=={{header|Wren}}==
Wren doesn't have a ''do/while'' loop as such but we can simulate it using an infinite loop with a final conditional break.
<syntaxhighlight lang="ecmascript">var v = 0
while (true) {
v = v + 1
System.print(v)
if (v%6 == 0) break
}</syntaxhighlight>
{{out}}
<pre>
1
2
3
4
5
6
</pre>
It can also be simulated ''without'' using a break statement as follows:
<syntaxhighlight lang="ecmascript">var value = 0
var ok = true
while (ok) {
value = value + 1
System.print(value)
ok = value%6 != 0
}</syntaxhighlight>
 
{{out}}
<pre>
Same as before.
</pre>
 
=={{header|V (Vlang)}}==
Line 3,354 ⟶ 3,393:
println(n3) // prt 8
}</syntaxhighlight>
 
=={{header|Wren}}==
Wren doesn't have a ''do/while'' loop as such but we can simulate it using an infinite loop with a final conditional break.
<syntaxhighlight lang="wren">var v = 0
while (true) {
v = v + 1
System.print(v)
if (v%6 == 0) break
}</syntaxhighlight>
{{out}}
<pre>
1
2
3
4
5
6
</pre>
It can also be simulated ''without'' using a break statement as follows:
<syntaxhighlight lang="wren">var value = 0
var ok = true
while (ok) {
value = value + 1
System.print(value)
ok = value%6 != 0
}</syntaxhighlight>
 
{{out}}
<pre>
Same as before.
</pre>
 
=={{header|X86 Assembly}}==