Loops/Do-while: Difference between revisions
m
Moved Wren entry into correct alphabetical order.
m (Update lang example: Improve control flow statements) |
m (Moved Wren entry into correct alphabetical order.) |
||
(9 intermediate revisions by 7 users not shown) | |||
Line 755:
60 END
</syntaxhighlight>
The [[#Minimal BASIC|Minimal BASIC]] solution works without any changes.
==={{header|NS-HUBASIC}}===
Line 806 ⟶ 809:
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 929 ⟶ 935:
std::cout << val << std::endl;
}while(val % 6 != 0);</syntaxhighlight>
=={{header|C3}}==
In this example we use default zero initialization of locals in C3.
do
{
io::printn(++val);
}
=={{header|Chapel}}==
Line 1,050 ⟶ 1,065:
{{out}}
<pre>1 2 3 4 5 6 </pre>
=={{header|Dart}}==
int val = 0;
do {
val++;
} while (val % 6 != 0);
}
=={{header|dc}}==
Line 1,164 ⟶ 1,189:
value += 1
print value
until
.
</syntaxhighlight>
Line 2,300 ⟶ 2,325:
inc val
echo val</syntaxhighlight>
=={{header|Nu}}==
<syntaxhighlight lang="nu">
mut n = 0
$n += 1
print $n
}
</syntaxhighlight>
=={{header|Oberon-2}}==
Line 2,808 ⟶ 2,843:
To ensure at least one loop, <code>DO</code>..<code>UNTIL</code>..<code>END</code> must be used rather than <code>WHILE</code>..<code>REPEAT</code>..<code>END</code>. To actually print (on paper) instead of pushing in the stack successive results, the <code>DUP</code> instruction inside the loop shall be replaced by <code>PR1</code>
≪ 0
'''DO'''
1 + DUP
'''UNTIL''' DUP 6 MOD 0 == '''END'''
DROP
≫
Line 2,833 ⟶ 2,868:
|}
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 3,256 ⟶ 3,291:
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,344 ⟶ 3,348:
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}}==
|