Loops/Do-while: Difference between revisions
Content deleted Content added
m RPL typo |
m Moved FutureBasic entry out of the BASIC group |
||
(14 intermediate revisions by 9 users not shown) | |||
Line 245:
</pre>
===
{{works with|A60}}
While a judicious "goto" may
<syntaxhighlight lang="algol60">
begin
Line 255:
i := 0;
another := true;
for i := i
begin
i := i + 1;
outinteger(1,i);
comment -
if i = (i div 6) * 6 then another := false;
end;
Line 639 ⟶ 640:
<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>
value = 0
repeat
value += 1
print value
until
.
</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,843 ⟶ 2,889:
|}
During November 2005, Yukihiro Matsumoto, the creator of Ruby, [https://web.archive.org/web/20220322235407/http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/6741 regretted this loop feature] and [https://web.archive.org/web/20220322235418/http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/6745 suggested using Kernel#loop].
{| class="wikitable"
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|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}}==
|