Loops/Continue: Difference between revisions

added RPL
(GDScript)
(added RPL)
 
(14 intermediate revisions by 10 users not shown)
Line 456:
}
quit</syntaxhighlight>
 
=={{header|BCPL}}==
In BCPL, the <tt>continue</tt> statement is named <tt>loop</tt>.
 
<syntaxhighlight lang="bcpl">get "libhdr"
 
let start() be
for i = 1 to 10
$( writen(i)
if i rem 5 = 0
$( wrch('*N')
loop
$)
writes(", ")
$)</syntaxhighlight>
{{out}}
<pre>1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
=={{header|Befunge}}==
Line 531 ⟶ 549:
}
cout << ", ";
}</syntaxhighlight>
 
=={{header|C3}}==
{{trans|Java}}
<syntaxhighlight lang="c3">for (int i = 1; i <= 10; i++)
{
io::print(i);
if (i % 5 == 0)
{
io::printn();
continue;
}
io::print(", ");
}</syntaxhighlight>
 
Line 657 ⟶ 688:
(return-from continue))
(write-string ", ")))</syntaxhighlight>
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
var n: uint8 := 0;
while n < 10 loop
n := n + 1;
print_i8(n);
if n % 5 == 0 then
print_nl();
continue;
end if;
print(", ");
end loop;</syntaxhighlight>
{{out}}
<pre>1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
=={{header|D}}==
Line 809 ⟶ 857:
Loops.continue</syntaxhighlight>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
for int i = 1; i <= 10; ++i
write(i)
if i % 5 == 0
writeLine()
continue
end
write(", ")
end
</syntaxhighlight>
{{out}}
<pre>
Line 1,235 ⟶ 1,300:
 
Though it's rare to see J code like this.
 
=={{header|Jakt}}==
<syntaxhighlight lang="jakt">
fn main() {
for i in 1..11 {
if i % 5 == 0 {
println("{}", i)
continue
}
print("{}, ", i)
}
}
</syntaxhighlight>
 
=={{header|Java}}==
Line 1,379 ⟶ 1,457:
 
=={{header|langur}}==
{{works with|langur|0.8.1}}
<syntaxhighlight lang="langur">for .i of 10 {
write .i
Line 1,393 ⟶ 1,470:
'Hello, World!' // never gets executed
^}</syntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
i is number
n is number
 
procedure:
for i from 1 to 11 step 1 do
display i
modulo i by 5 in n
if n is equal to 0 then
display lf
continue
end if
display ", "
repeat</syntaxhighlight>
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Lingo}}==
Line 1,538 ⟶ 1,635:
)
)$</syntaxhighlight>
Using sprint and newline
<syntaxhighlight lang="maxima">
for n:1 thru 10 do (
sprint(n),
if n=5 then newline())$
</syntaxhighlight>
 
=={{header|MAXScript}}==
Line 1,690 ⟶ 1,793:
40 PRINT ",";
50 NEXT</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
for i in 1..10 {
print -n $i
if $i mod 5 == 0 {
print ""
continue
}
print -n ", "
}
</syntaxhighlight>
 
=={{header|Objeck}}==
Line 2,118 ⟶ 2,233:
next
</syntaxhighlight>
 
=={{header|RPL}}==
You need an <code>IF..THEN..ELSE</code> structure to do that in RPL.
« ""
1 10 '''FOR''' j
j +
'''IF''' j 5 MOD '''THEN''' ", " + '''ELSE''' "" '''END'''
'''NEXT''' DROP
» '<span style="color:blue">TASK</span>' STO
 
=={{header|Ruby}}==
Line 2,276 ⟶ 2,400:
<syntaxhighlight lang="smalltalk">valueWithExit
^ self value:[^ nil]</syntaxhighlight>
 
=={{header|SNOBOL4}}==
 
SNOBOL4 has no looping statements or conditional statements. Indeed the only branching facilities it has are:
 
* Unconditional branch to label. <code>:(LABEL)</code>
* Branch to label on success. <code>:S(LABEL)</code>
* Branch to label on failure. <code>:F(LABEL)</code>
 
(The success/failure labels can both be in the branching clause.)
 
Despite this, any looping structure can be performed by careful use of these.
 
<syntaxhighlight lang="snobol4">
line =
i = 1
LOOP le(i, 10) :F(LOOP.END)
line = line i
eq(remdr(i, 5), 0) :S(LOOP.OUT)
line = line ', ' :(LOOP.INC)
LOOP.OUT OUTPUT = line
line =
LOOP.INC i = i + 1 :(LOOP)
LOOP.END OUTPUT = line
 
END
</syntaxhighlight>
 
{{Out}}
 
<pre>
$ snobol4 junk.sno
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Spin}}==
Line 2,536 ⟶ 2,695:
=={{header|Wren}}==
From v0.4.0 Wren has a ''continue'' keyword which works in the expected fashion.
<syntaxhighlight lang="ecmascriptwren">for (i in 1..10) {
System.write(i)
if (i%5 == 0) {
1,150

edits