Loops/Do-while: Difference between revisions
m
Moved Wren entry into correct alphabetical order.
(C3 Added) |
m (Moved Wren entry into correct alphabetical order.) |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 937:
=={{header|C3}}==
In this example we use default zero initialization of locals in C3.
<syntaxhighlight lang="c3">int val;
do
Line 943 ⟶ 944:
}
while (val % 6 != 0);</syntaxhighlight>
=={{header|Chapel}}==
<syntaxhighlight lang="chapel">var val = 0;
Line 1,187 ⟶ 1,189:
value += 1
print value
until
.
</syntaxhighlight>
Line 2,323 ⟶ 2,325:
inc val
echo val</syntaxhighlight>
mut n = 0
$n += 1
print $n
}
=={{header|Oberon-2}}==
Line 3,279 ⟶ 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,367 ⟶ 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.
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:
▲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}}==
|