Loops/Continue: Difference between revisions

From Rosetta Code
Content added Content deleted
(added RPL)
 
(40 intermediate revisions by 25 users not shown)
Line 1: Line 1:
{{task|Iteration}}
{{task|Iteration}}
[[Category:Loop modifiers]]
[[Category:Loop modifiers]]
{{omit from|EasyLang|No continue statement}}
{{omit from|GUISS}}
{{omit from|GUISS}}
{{omit from|M4}}
{{omit from|M4}}
Line 35: Line 36:
{{trans|Python}}
{{trans|Python}}


<lang 11l>L(i) 1..10
<syntaxhighlight lang="11l">L(i) 1..10
I i % 5 == 0
I i % 5 == 0
print(i)
print(i)
L.continue
L.continue
print(i, end' ‘, ’)</lang>
print(i, end' ‘, ’)</syntaxhighlight>


{{out}}
{{out}}
Line 48: Line 49:


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
<lang 360asm>* Loops/Continue 12/08/2015
<syntaxhighlight lang="360asm">* Loops/Continue 12/08/2015
LOOPCONT CSECT
LOOPCONT CSECT
USING LOOPCONT,R12
USING LOOPCONT,R12
Line 79: Line 80:
XDEC DS CL16
XDEC DS CL16
YREGS
YREGS
END LOOPCONT</lang>
END LOOPCONT</syntaxhighlight>
{{out}}
{{out}}
<pre> 1, 2, 3, 4, 5
<pre> 1, 2, 3, 4, 5
Line 103: Line 104:
forgo the null statement.
forgo the null statement.


<lang ada>with Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO;
use Ada.Text_IO;
use Ada.Text_IO;


Line 117: Line 118:
<<Continue>> --Ada 2012 no longer requires a statement after the label
<<Continue>> --Ada 2012 no longer requires a statement after the label
end loop;
end loop;
end Loop_Continue;</lang>
end Loop_Continue;</syntaxhighlight>


'''N.''' This is a more true-to-Ada strategy for 'continue' comprising of an outer iteration loop and an inner labeled single-pass loop. This is a safer strategy than using goto which could be problematic when dealing with complex nested loops.
'''N.''' This is a more true-to-Ada strategy for 'continue' comprising of an outer iteration loop and an inner labeled single-pass loop. This is a safer strategy than using goto which could be problematic when dealing with complex nested loops.


<lang ada>with Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO;
use Ada.Text_IO;
use Ada.Text_IO;


Line 138: Line 139:
end loop Print_Element;
end loop Print_Element;
end loop Print_All;
end loop Print_All;
end Loop_Continue;</lang>
end Loop_Continue;</syntaxhighlight>


=={{header|Agena}}==
=={{header|Agena}}==
Agena doesn't have a continue statement, conditional statements can be used instead.
Agena doesn't have a continue statement, conditional statements can be used instead.
<lang agena>for i to 10 do
<syntaxhighlight lang="agena">for i to 10 do
write( i );
write( i );
if i % 5 = 0
if i % 5 = 0
Line 148: Line 149:
else write( ", " )
else write( ", " )
fi
fi
od</lang>
od</syntaxhighlight>


=={{header|Aikido}}==
=={{header|Aikido}}==
<lang aikido>foreach i 1..10 {
<syntaxhighlight lang="aikido">foreach i 1..10 {
print (i)
print (i)
if ((i % 5) == 0) {
if ((i % 5) == 0) {
Line 158: Line 159:
}
}
print (", ")
print (", ")
}</lang>
}</syntaxhighlight>


=={{header|ALGOL 60}}==
=={{header|ALGOL 60}}==
Line 182: Line 183:
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
[[ALGOL 68]] has no continue reserved word, nor does it need one. The continue reserved word is only syntactic sugar for operations that can be achieved without it as in the following example:
[[ALGOL 68]] has no continue reserved word, nor does it need one. The continue reserved word is only syntactic sugar for operations that can be achieved without it as in the following example:
<lang algol68>FOR i FROM 1 TO 10 DO
<syntaxhighlight lang="algol68">FOR i FROM 1 TO 10 DO
print ((i,
print ((i,
IF i MOD 5 = 0 THEN
IF i MOD 5 = 0 THEN
Line 190: Line 191:
FI
FI
))
))
OD</lang>
OD</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 199: Line 200:
=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
Algol W doesn't have a continue statement - conditional statements can be used instead.
Algol W doesn't have a continue statement - conditional statements can be used instead.
<lang algolw>begin
<syntaxhighlight lang="algolw">begin
i_w := 1; s_w := 0; % set output format %
i_w := 1; s_w := 0; % set output format %
for i := 1 until 10 do begin
for i := 1 until 10 do begin
Line 207: Line 208:
else writeon( ", " )
else writeon( ", " )
end for_i
end for_i
end.</lang>
end.</syntaxhighlight>

=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">
set table to {return}
repeat with i from 1 to 10
if i < 5 or (i ≥ 6 and i < 10) then
set end of table to i & ", "
else if i = 5 or i = 10 then
set end of table to i & return
end if
end repeat
return table as string
</syntaxhighlight>
{{out}}
<pre>
"
1, 2, 3, 4, 5
6, 7, 8, 9, 10
"
</pre>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>loop 1..10 'i [
<syntaxhighlight lang="rebol">loop 1..10 'i [
prints i
prints i
if 0 = i%5 [
if 0 = i%5 [
Line 218: Line 239:
]
]
prints ", "
prints ", "
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 224: Line 245:
<pre>1, 2, 3, 4, 5
<pre>1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
6, 7, 8, 9, 10</pre>

=={{header|Asymptote}}==
Asymptote's control structures are similar to those in C/C++
<syntaxhighlight lang="asymptote">for(int i = 1; i <= 10; ++i) {
write(i, suffix=none);
if(i % 5 == 0) {
write("");
continue;
} else {
write(", ", suffix=none);
}
}</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang autohotkey>Loop, 10 {
<syntaxhighlight lang="autohotkey">Loop, 10 {
Delimiter := (A_Index = 5) || (A_Index = 10) ? "`n":", "
Delimiter := (A_Index = 5) || (A_Index = 10) ? "`n":", "
Index .= A_Index . Delimiter
Index .= A_Index . Delimiter
}
}
MsgBox %Index%</lang>
MsgBox %Index%</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<lang awk>BEGIN {
<syntaxhighlight lang="awk">BEGIN {
for(i=1; i <= 10; i++) {
for(i=1; i <= 10; i++) {
printf("%d", i)
printf("%d", i)
Line 242: Line 275:
printf(", ")
printf(", ")
}
}
}</lang>
}</syntaxhighlight>


=={{header|BASIC}}==
=={{header|BASIC}}==


==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<lang ApplesoftBasic> 10 FOR I = 1 TO 10
<syntaxhighlight lang="applesoftbasic"> 10 FOR I = 1 TO 10
20 PRINT I;
20 PRINT I;
30 IF I - INT (I / 5) * 5 = 0 THEN PRINT : GOTO 50"CONTINUE
30 IF I - INT (I / 5) * 5 = 0 THEN PRINT : GOTO 50"CONTINUE
40 PRINT ", ";
40 PRINT ", ";
50 NEXT</lang>
50 NEXT</syntaxhighlight>

==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">for i = 1 to 10
print string(i);
if i mod 5 = 0 then
print
continue for
end if
print ", ";
next
print
end</syntaxhighlight>


==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
BBC BASIC doesn't have a 'continue' statement so the remainder of the loop must be made conditional.
BBC BASIC doesn't have a 'continue' statement so the remainder of the loop must be made conditional.
<lang bbcbasic> FOR i% = 1 TO 10
<syntaxhighlight lang="bbcbasic"> FOR i% = 1 TO 10
PRINT ; i% ;
PRINT ; i% ;
IF i% MOD 5 = 0 PRINT ELSE PRINT ", ";
IF i% MOD 5 = 0 PRINT ELSE PRINT ", ";
NEXT</lang>
NEXT</syntaxhighlight>


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
Commodore BASIC also doesn't have a 'continue' statement. In this example, a GOTO statement is used to simulate 'CONTINUE'. However, Commodore BASIC doesn't have a modulo (remainder) operator, so value of I/5 is check against INT(I/5). If they are the same, the remainder is zero.
Commodore BASIC also doesn't have a 'continue' statement. In this example, a GOTO statement is used to simulate 'CONTINUE'. However, Commodore BASIC doesn't have a modulo (remainder) operator, so value of I/5 is check against INT(I/5). If they are the same, the remainder is zero.
<lang qbasic>10 FOR I = 1 to 10
<syntaxhighlight lang="qbasic">10 FOR I = 1 to 10
20 PRINT I;
20 PRINT I;
30 IF INT(I/5) = I/5 THEN PRINT : GOTO 50
30 IF INT(I/5) = I/5 THEN PRINT : GOTO 50
40 PRINT ", ";
40 PRINT ", ";
50 NEXT</lang>
50 NEXT</syntaxhighlight>


==={{header|FreeBASIC}}===
==={{header|FreeBASIC}}===
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
For i As Integer = 1 To 10
For i As Integer = 1 To 10
Print Str(i);
Print Str(i);
Line 280: Line 325:


Print
Print
Sleep</lang>
Sleep</syntaxhighlight>


{{out}}
{{out}}
Line 289: Line 334:


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<lang IS-BASIC>100 FOR I=1 TO 10
<syntaxhighlight lang="is-basic">100 FOR I=1 TO 10
110 PRINT STR$(I);
110 PRINT STR$(I);
120 IF MOD(I,5)=0 THEN
120 IF MOD(I,5)=0 THEN
Line 296: Line 341:
150 PRINT ", ";
150 PRINT ", ";
160 END IF
160 END IF
170 NEXT</lang>
170 NEXT</syntaxhighlight>


==={{header|Liberty BASIC}}===
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">
<lang lb>
for i =1 to 10
for i =1 to 10
if i mod 5 <>0 then print i; ", "; else print i
if i mod 5 <>0 then print i; ", "; else print i
next i
next i
end
end
</syntaxhighlight>
</lang>


==={{header|PureBasic}}===
==={{header|PureBasic}}===
<lang purebasic>OpenConsole()
<syntaxhighlight lang="purebasic">OpenConsole()


For i.i = 1 To 10
For i.i = 1 To 10
Line 318: Line 363:
Next
Next


Repeat: Until Inkey() <> ""</lang>
Repeat: Until Inkey() <> ""</syntaxhighlight>


==={{header|QB64}}===
==={{header|QB64}}===
<lang qb64>Dim i As Integer
<syntaxhighlight lang="qb64">Dim i As Integer
For i = 1 To 10
For i = 1 To 10
Print LTrim$(Str$(i));
Print LTrim$(Str$(i));
Line 329: Line 374:
End If
End If
Print ", ";
Print ", ";
Next</lang>
Next</syntaxhighlight>


==={{header|Run BASIC}}===
==={{header|Run BASIC}}===
{{works with|QBasic}}
<lang runbasic>for i = 1 to 10
<syntaxhighlight lang="runbasic">for i = 1 to 10
if i mod 5 <> 0 then print i;", "; else print i
if i mod 5 <> 0 then print i;", "; else print i
next i</lang>
next i</syntaxhighlight>


==={{header|Sinclair ZX81 BASIC}}===
==={{header|Sinclair ZX81 BASIC}}===
This probably isn't the most idiomatic way to produce the specified output—but it does illustrate ZX81 BASIC's equivalent of <code>if <condition> continue</code>, which is <code>IF <condition> THEN NEXT <loop-control variable></code>.
This probably isn't the most idiomatic way to produce the specified output—but it does illustrate ZX81 BASIC's equivalent of <code>if <condition> continue</code>, which is <code>IF <condition> THEN NEXT <loop-control variable></code>.
<lang>10 FOR I=1 TO 10
<syntaxhighlight lang="text">10 FOR I=1 TO 10
20 PRINT I;
20 PRINT I;
30 IF I/5=INT (I/5) THEN PRINT
30 IF I/5=INT (I/5) THEN PRINT
40 IF I/5=INT (I/5) THEN NEXT I
40 IF I/5=INT (I/5) THEN NEXT I
50 PRINT ", ";
50 PRINT ", ";
60 NEXT I</lang>
60 NEXT I</syntaxhighlight>


==={{header|TI-89 BASIC}}===
==={{header|TI-89 BASIC}}===
<lang ti-89>count()
<syntaxhighlight lang="ti-89">count()
Prgm
Prgm
""→s
""→s
Line 358: Line 404:
s&", "→s
s&", "→s
EndFor
EndFor
EndPrgm</lang>
EndPrgm</syntaxhighlight>


Ti-89 lacks support for multi-argument display command or controlling the print position so that one can print several data on the same line. The display command (Disp) only accepts one argument and prints it on a single line (causing a line a feed at the end, so that the next Disp command will print in the next line). The solution is appending data to a string (s), using the concatenator operator (&), by converting numbers to strings, and then printing the string at the end of the line.
Ti-89 lacks support for multi-argument display command or controlling the print position so that one can print several data on the same line. The display command (Disp) only accepts one argument and prints it on a single line (causing a line a feed at the end, so that the next Disp command will print in the next line). The solution is appending data to a string (s), using the concatenator operator (&), by converting numbers to strings, and then printing the string at the end of the line.

==={{header|True BASIC}}===
<syntaxhighlight lang="basic">FOR i = 1 TO 10
PRINT STR$(i);
IF REMAINDER(i, 5) = 0 THEN
PRINT
ELSE !No existe el comando CONTINUE
PRINT ", ";
END IF
NEXT i
PRINT
END</syntaxhighlight>


==={{header|VB-DOS, PDS}}===
==={{header|VB-DOS, PDS}}===
<syntaxhighlight lang="qbasic">
<lang QBASIC>
OPTION EXPLICIT
OPTION EXPLICIT


Line 373: Line 431:
IF (i MOD 5) THEN PRINT ","; ELSE PRINT
IF (i MOD 5) THEN PRINT ","; ELSE PRINT
NEXT i
NEXT i
END</lang>
END</syntaxhighlight>


==={{header|Visual Basic .NET}}===
==={{header|Visual Basic .NET}}===
<lang vbnet>For i = 1 To 10
<syntaxhighlight lang="vbnet">For i = 1 To 10
Console.Write(i)
Console.Write(i)
If i Mod 5 = 0 Then
If i Mod 5 = 0 Then
Line 383: Line 441:
Console.Write(", ")
Console.Write(", ")
End If
End If
Next</lang>
Next</syntaxhighlight>


=={{header|bc}}==
=={{header|bc}}==
Line 389: Line 447:


{{works with|OpenBSD bc}}
{{works with|OpenBSD bc}}
<lang bc>for (i = 1; i <= 10; i++) {
<syntaxhighlight lang="bc">for (i = 1; i <= 10; i++) {
print i
print i
if (i % 5) {
if (i % 5) {
Line 397: Line 455:
print "\n"
print "\n"
}
}
quit</lang>
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}}==
=={{header|Befunge}}==
Befunge outputs numbers with a space after them, so the formatting is slightly off in this version.
Befunge outputs numbers with a space after them, so the formatting is slightly off in this version.
<syntaxhighlight lang="befunge">
<lang Befunge>
1>:56+\`#v_@
1>:56+\`#v_@
+v %5:.:<
+v %5:.:<
Line 408: Line 484:
>" ,",,v
>" ,",,v
^ <
^ <
</syntaxhighlight>
</lang>


This version outputs a 'backspace' ASCII character to try to correct the format, but it may or may not work depending on if the character is accounted for by the output
This version outputs a 'backspace' ASCII character to try to correct the format, but it may or may not work depending on if the character is accounted for by the output
<syntaxhighlight lang="befunge">
<lang Befunge>
1>:56+\`#v_@
1>:56+\`#v_@
+v5:,8.:<
+v5:,8.:<
Line 418: Line 494:
>" ,",v
>" ,",v
^ ,<
^ ,<
</syntaxhighlight>
</lang>


=={{header|Bracmat}}==
=={{header|Bracmat}}==
Bracmat has no continue statement.
Bracmat has no continue statement.
<lang bracmat>( 0:?i
<syntaxhighlight lang="bracmat">( 0:?i
& whl
& whl
' ( 1+!i:~>10:?i
' ( 1+!i:~>10:?i
Line 432: Line 508:
)
)
)
)
);</lang>
);</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
{{trans|C++}}
{{trans|C++}}
<lang c>for(int i = 1;i <= 10; i++){
<syntaxhighlight lang="c">for(int i = 1;i <= 10; i++){
printf("%d", i);
printf("%d", i);
if(i % 5 == 0){
if(i % 5 == 0){
Line 443: Line 519:
}
}
printf(", ");
printf(", ");
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
{{trans|Java}}
{{trans|Java}}
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


class Program {
class Program {
Line 462: Line 538:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
{{trans|Java}}
{{trans|Java}}
<lang cpp>for(int i = 1;i <= 10; i++){
<syntaxhighlight lang="cpp">for(int i = 1;i <= 10; i++){
cout << i;
cout << i;
if(i % 5 == 0){
if(i % 5 == 0){
Line 473: Line 549:
}
}
cout << ", ";
cout << ", ";
}</lang>
}</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>


=={{header|Chapel}}==
=={{header|Chapel}}==
<lang chapel>for i in 1..10 {
<syntaxhighlight lang="chapel">for i in 1..10 {
write(i);
write(i);
if i % 5 == 0 then {
if i % 5 == 0 then {
Line 483: Line 572:
}
}
write(", ");
write(", ");
}</lang>
}</syntaxhighlight>


=={{header|Clipper}}==
=={{header|Clipper}}==
Line 489: Line 578:


Works as is with Harbour 3.0.0 (Rev. 16951)
Works as is with Harbour 3.0.0 (Rev. 16951)
<lang visualfoxpro>FOR i := 1 TO 10
<syntaxhighlight lang="visualfoxpro">FOR i := 1 TO 10
?? i
?? i
IF i % 5 == 0
IF i % 5 == 0
Line 496: Line 585:
ENDIF
ENDIF
?? ", "
?? ", "
NEXT</lang>
NEXT</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
Clojure doesn't have a continue keyword. It has a recur keyword, although I prefer to work with ranges in this case.
Clojure doesn't have a continue keyword. It has a recur keyword, although I prefer to work with ranges in this case.
<lang clojure>(doseq [n (range 1 11)]
<syntaxhighlight lang="clojure">(doseq [n (range 1 11)]
(print n)
(print n)
(if (zero? (rem n 5))
(if (zero? (rem n 5))
(println)
(println)
(print ", ")))</lang>
(print ", ")))</syntaxhighlight>


To address the task, however, here's an example loop/recur:
To address the task, however, here's an example loop/recur:
<lang clojure>(loop [xs (range 1 11)]
<syntaxhighlight lang="clojure">(loop [xs (range 1 11)]
(when-let [x (first xs)]
(when-let [x (first xs)]
(print x)
(print x)
Line 513: Line 602:
(println)
(println)
(print ", "))
(print ", "))
(recur (rest xs))))</lang>
(recur (rest xs))))</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. loop-continue.
PROGRAM-ID. loop-continue.


Line 536: Line 625:


GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


Note: COBOL does have a <code>CONTINUE</code> verb, but this is a no-operation statement used in <code>IF</code> and <code>EVALUATE</code> statements.
Note: COBOL does have a <code>CONTINUE</code> verb, but this is a no-operation statement used in <code>IF</code> and <code>EVALUATE</code> statements.
Line 542: Line 631:
=={{header|ColdFusion}}==
=={{header|ColdFusion}}==
Remove the leading space from the line break tag.
Remove the leading space from the line break tag.
<lang cfm><cfscript>
<syntaxhighlight lang="cfm"><cfscript>
for( i = 1; i <= 10; i++ )
for( i = 1; i <= 10; i++ )
{
{
Line 553: Line 642:
writeOutput( "," );
writeOutput( "," );
}
}
</cfscript></lang>
</cfscript></syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 561: Line 650:
The second uses the implicit <code>tagbody</code> and <code>go</code>.
The second uses the implicit <code>tagbody</code> and <code>go</code>.
The third is a do loop with conditionals outside of the output functions.
The third is a do loop with conditionals outside of the output functions.
<lang lisp>(do ((i 1 (1+ i)))
<syntaxhighlight lang="lisp">(do ((i 1 (1+ i)))
((> i 10))
((> i 10))
(format t "~a~:[, ~;~%~]" i (zerop (mod i 5))))
(format t "~a~:[, ~;~%~]" i (zerop (mod i 5))))
Line 579: Line 668:
(if (zerop (mod i 5))
(if (zerop (mod i 5))
(terpri)
(terpri)
(write-string ", ")))</lang>
(write-string ", ")))</syntaxhighlight>


These use the <code>loop</code> iteration form, which does not contain an implicit tagbody (though one could be explicitly included).
These use the <code>loop</code> iteration form, which does not contain an implicit tagbody (though one could be explicitly included).
Line 585: Line 674:
the second uses <code>block</code>/<code>return-from</code> to obtain the effect of skipping the rest of the code in the <code>block</code> which makes up the entire loop body.
the second uses <code>block</code>/<code>return-from</code> to obtain the effect of skipping the rest of the code in the <code>block</code> which makes up the entire loop body.


<lang lisp>(loop for i from 1 to 10
<syntaxhighlight lang="lisp">(loop for i from 1 to 10
do (write i)
do (write i)
if (zerop (mod i 5))
if (zerop (mod i 5))
Line 598: Line 687:
(terpri)
(terpri)
(return-from continue))
(return-from continue))
(write-string ", ")))</lang>
(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}}==
=={{header|D}}==
<lang d>import std.stdio;
<syntaxhighlight lang="d">import std.stdio;


void main() {
void main() {
Line 612: Line 718:
write(", ");
write(", ");
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>1, 2, 3, 4, 5
<pre>1, 2, 3, 4, 5
Line 618: Line 724:


===Shorter version===
===Shorter version===
<syntaxhighlight lang="d">
<lang d>
import std.stdio;
import std.stdio;


Line 625: Line 731:
foreach(i; 1..11) i % 5 ? writef("%s, ", i) : writeln(i);
foreach(i; 1..11) i % 5 ? writef("%s, ", i) : writeln(i);
}
}
</syntaxhighlight>
</lang>


=={{header|dc}}==
=={{header|dc}}==
Line 635: Line 741:
{{works with|OpenBSD dc}}
{{works with|OpenBSD dc}}


<lang dc>1 si # i = 1
<syntaxhighlight lang="dc">1 si # i = 1
[2Q]sA # A = code to break loop
[2Q]sA # A = code to break loop
[[, ]P 1J]sB # B = code to print comma, continue loop
[[, ]P 1J]sB # B = code to print comma, continue loop
Line 646: Line 752:
li 1 + si # i += 1
li 1 + si # i += 1
li 10!<C # continue loop if 10 >= i
li 10!<C # continue loop if 10 >= i
]sC li 10!<C # enter loop if 10 >= i</lang>
]sC li 10!<C # enter loop if 10 >= i</syntaxhighlight>


This program uses <tt>J</tt> and <tt>M</tt> to force the next iteration of a loop.
This program uses <tt>J</tt> and <tt>M</tt> to force the next iteration of a loop.
Line 654: Line 760:
=={{header|Delphi}}==
=={{header|Delphi}}==


<lang Delphi>program DoLoop(output);
<syntaxhighlight lang="delphi">program DoLoop(output);
var
var
i: integer;
i: integer;
Line 668: Line 774:
write(', ');
write(', ');
end;
end;
end.</lang>
end.</syntaxhighlight>


{{Out}}
{{Out}}
Line 678: Line 784:
=={{header|DWScript}}==
=={{header|DWScript}}==


<lang Delphi>var i : Integer;
<syntaxhighlight lang="delphi">var i : Integer;


for i := 1 to 10 do begin
for i := 1 to 10 do begin
Line 687: Line 793:
end;
end;
Print(', ');
Print(', ');
end;</lang>
end;</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==
Line 693: Line 799:
{{trans|Swift}}
{{trans|Swift}}


<lang Dyalect>for i in 1..10 {
<syntaxhighlight lang="dyalect">for i in 1..10 {
print(i, terminator: "")
print(i, terminator: "")
if i % 5 == 0 {
if i % 5 == 0 {
Line 700: Line 806:
}
}
print(", ", terminator: "")
print(", ", terminator: "")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 710: Line 816:


===Direct Approach===
===Direct Approach===
<lang ela>open monad io
<syntaxhighlight lang="ela">open monad io
loop n =
loop n =
Line 722: Line 828:
| else = ", "
| else = ", "


_ = loop 1 ::: IO</lang>
_ = loop 1 ::: IO</syntaxhighlight>


===Using list===
===Using list===
<lang ela>open monad io
<syntaxhighlight lang="ela">open monad io
loop [] = return ()
loop [] = return ()
Line 735: Line 841:
| else = ", "
| else = ", "
_ = loop [1..10] ::: IO</lang>
_ = loop [1..10] ::: IO</syntaxhighlight>


This version is more generic and can work for any given range of values.
This version is more generic and can work for any given range of values.


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>defmodule Loops do
<syntaxhighlight lang="elixir">defmodule Loops do
def continue do
def continue do
Enum.each(1..10, fn i ->
Enum.each(1..10, fn i ->
Line 749: Line 855:
end
end


Loops.continue</lang>
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}}
{{out}}
<pre>
<pre>
Line 758: Line 881:


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>%% Implemented by Arjun Sunel
<syntaxhighlight lang="erlang">%% Implemented by Arjun Sunel
-module(continue).
-module(continue).
-export([main/0, for_loop/1]).
-export([main/0, for_loop/1]).
Line 779: Line 902:
for_loop(N+1)
for_loop(N+1)
end.
end.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>1, 2, 3, 4, 5
<pre>1, 2, 3, 4, 5
Line 786: Line 909:


=={{header|ERRE}}==
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
FOR I=1 TO 10 DO
FOR I=1 TO 10 DO
PRINT(I;CHR$(29);) ! printing a numeric value leaves a blank after it
PRINT(I;CHR$(29);) ! printing a numeric value leaves a blank after it
Line 797: Line 920:
END FOR
END FOR
PRINT
PRINT
</syntaxhighlight>
</lang>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.3, 4.0.0 or later}}
{{works with|Euphoria|4.0.3, 4.0.0 or later}}
<lang euphoria>include std\console.e --only for any_key to make running command window easier on windows
<syntaxhighlight lang="euphoria">include std\console.e --only for any_key to make running command window easier on windows


for i = 1 to 10 do
for i = 1 to 10 do
Line 811: Line 934:
end if
end if
end for
end for
any_key()</lang>
any_key()</syntaxhighlight>
Version without newline after 10 below.
Version without newline after 10 below.
<lang euphoria>include std\console.e --only for any_key to make running command window easier on windows
<syntaxhighlight lang="euphoria">include std\console.e --only for any_key to make running command window easier on windows


for i = 1 to 10 do
for i = 1 to 10 do
Line 831: Line 954:
end for
end for
any_key()
any_key()
</syntaxhighlight>
</lang>


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
Line 837: Line 960:
In any case, it is not needed to complete this task.
In any case, it is not needed to complete this task.
==={{trans|Ada}}===
==={{trans|Ada}}===
<lang fsharp>for i in 1 .. 10 do
<syntaxhighlight lang="fsharp">for i in 1 .. 10 do
printf "%d" i
printf "%d" i
if i % 5 = 0 then
if i % 5 = 0 then
printf "\n"
printf "\n"
else
else
printf ", "</lang>
printf ", "</syntaxhighlight>
===Using [[Comma quibbling#The Function]]===
===Using [[Comma quibbling#The Function]]===
<lang fsharp>
<syntaxhighlight lang="fsharp">
let fN g=quibble (Seq.initInfinite(fun n ->if (n+1)%5=0 || (n+1)=List.length g then "\n" else ", ")) g
let fN g=quibble (Seq.initInfinite(fun n ->if (n+1)%5=0 || (n+1)=List.length g then "\n" else ", ")) g
fN [1] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
fN [1] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
Line 850: Line 973:
fN [1..10] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
fN [1..10] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
fN [1..11] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
fN [1..11] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 865: Line 988:
=={{header|Factor}}==
=={{header|Factor}}==
There is no built-in <code>continue</code> in Factor.
There is no built-in <code>continue</code> in Factor.
<lang factor>1 10 [a,b] [
<syntaxhighlight lang="factor">1 10 [a,b] [
[ number>string write ]
[ number>string write ]
[ 5 mod 0 = "\n" ", " ? write ] bi
[ 5 mod 0 = "\n" ", " ? write ] bi
] each</lang>
] each</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==
Line 874: Line 997:
While and for loops support <code>continue</code> to jump back to begin the next iteration of the loop.
While and for loops support <code>continue</code> to jump back to begin the next iteration of the loop.


<lang fantom>
<syntaxhighlight lang="fantom">
class LoopsContinue
class LoopsContinue
{
{
Line 892: Line 1,015:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Forth}}==
=={{header|Forth}}==
Although this code solves the task, there is no portable equivalent to "continue" for either DO-LOOPs or BEGIN loops.
Although this code solves the task, there is no portable equivalent to "continue" for either DO-LOOPs or BEGIN loops.
<lang forth>: main
<syntaxhighlight lang="forth">: main
11 1 do
11 1 do
i dup 1 r.
i dup 1 r.
5 mod 0= if cr else [char] , emit space then
5 mod 0= if cr else [char] , emit space then
loop ;</lang>
loop ;</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
{{works with|Fortran|90 and later}}
<lang fortran>do i = 1, 10
<syntaxhighlight lang="fortran">do i = 1, 10
write(*, '(I0)', advance='no') i
write(*, '(I0)', advance='no') i
if ( mod(i, 5) == 0 ) then
if ( mod(i, 5) == 0 ) then
Line 911: Line 1,034:
end if
end if
write(*, '(A)', advance='no') ', '
write(*, '(A)', advance='no') ', '
end do</lang>
end do</syntaxhighlight>


{{works with|Fortran|77 and later}}
{{works with|Fortran|77 and later}}
<lang fortran>C WARNING: This program is not valid ANSI FORTRAN 77 code. It uses
<syntaxhighlight lang="fortran">C WARNING: This program is not valid ANSI FORTRAN 77 code. It uses
C one nonstandard character on the line labelled 5001. Many F77
C one nonstandard character on the line labelled 5001. Many F77
C compilers should be okay with it, but it is *not* standard.
C compilers should be okay with it, but it is *not* standard.
Line 980: Line 1,103:
5001 FORMAT (I3, ',', $)
5001 FORMAT (I3, ',', $)
C5001 FORMAT (I3, ',', ADVANCE='NO')
C5001 FORMAT (I3, ',', ADVANCE='NO')
END</lang>
END</syntaxhighlight>


===Relying instead upon the looping features of FORMAT===
===Relying instead upon the looping features of FORMAT===
For historical reasons, 6 is often the default unit number for standard output.
For historical reasons, 6 is often the default unit number for standard output.
<syntaxhighlight lang="fortran">
<lang Fortran>
WRITE (6,1) (I,I = 1,10)
WRITE (6,1) (I,I = 1,10)
1 FORMAT (4(1X,I0,","),1X,I0)
1 FORMAT (4(1X,I0,","),1X,I0)
END
END
</syntaxhighlight>
</lang>
Here the break and continuation comes through the workings of the FORMAT interpreter. The feature 4(etc) means four repetitions of the format items within the brackets, and as each datum from the WRITE statement arrives, it is aligned with the next format item that can receive a datum, the I-format specifier (here I0, which means an integer of only as many digits as are needed for the value) and until such a reciever is encountered, intervening format items are acted upon - 1X means "one space", and the quotes surround a text literal. Accordingly, the first datum generates a space, a one-digit value, and a comma, as does the second and so on. When the sixth datum is received, the end of the format statement has been reached, and the convention is to write the current line and start a new line of output, and further, go back in the FORMAT specification to the first-encountered open-bracket symbol (the rightmost) which in this case is not the beginning of the FORMAT statement but the one that has a repetition count of four in front of it, and, resume interpretation. When the last datum has been accepted, naturally, the line is printed.
Here the break and continuation comes through the workings of the FORMAT interpreter. The feature 4(etc) means four repetitions of the format items within the brackets, and as each datum from the WRITE statement arrives, it is aligned with the next format item that can receive a datum, the I-format specifier (here I0, which means an integer of only as many digits as are needed for the value) and until such a reciever is encountered, intervening format items are acted upon - 1X means "one space", and the quotes surround a text literal. Accordingly, the first datum generates a space, a one-digit value, and a comma, as does the second and so on. When the sixth datum is received, the end of the format statement has been reached, and the convention is to write the current line and start a new line of output, and further, go back in the FORMAT specification to the first-encountered open-bracket symbol (the rightmost) which in this case is not the beginning of the FORMAT statement but the one that has a repetition count of four in front of it, and, resume interpretation. When the last datum has been accepted, naturally, the line is printed.


Line 997: Line 1,120:


This sort of scheme facilitates a compact way of printing a table with a heading, where the WRITE statement simply pours forth the data and relies on something like FORMAT("heading",/,(complex details for one line)) - thus printing the table line-by-line with only the first line having the heading, a saving on having a write and format statement pair for the heading and a second pair for the table body.
This sort of scheme facilitates a compact way of printing a table with a heading, where the WRITE statement simply pours forth the data and relies on something like FORMAT("heading",/,(complex details for one line)) - thus printing the table line-by-line with only the first line having the heading, a saving on having a write and format statement pair for the heading and a second pair for the table body.

=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">include "NSLog.incl"

long num

for num = 1 to 10
if ( num mod 5 )
NSLog(@"%ld, \b",num)
else
NSLog(@"%ld",num)
end if
next

HandleEvents</syntaxhighlight>


=={{header|Gambas}}==
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=bf629ae9a09ffa1f5ecc95b89854b14b Click this link to run this code]'''
'''[https://gambas-playground.proko.eu/?gist=bf629ae9a09ffa1f5ecc95b89854b14b Click this link to run this code]'''
<lang gambas>Public Sub Main()
<syntaxhighlight lang="gambas">Public Sub Main()
Dim siCount As Short
Dim siCount As Short


Line 1,009: Line 1,147:
Next
Next


End</lang>
End</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 1,017: Line 1,155:


=={{header|GAP}}==
=={{header|GAP}}==
<lang gap>for i in [1 .. 11] do
<syntaxhighlight lang="gap">for i in [1 .. 11] do
if RemInt(i, 5) = 0 then
if RemInt(i, 5) = 0 then
Print(i, "\n");
Print(i, "\n");
Line 1,026: Line 1,164:


# 1, 2, 3, 4, 5
# 1, 2, 3, 4, 5
# 6, 7, 8, 9, 10</lang>
# 6, 7, 8, 9, 10</syntaxhighlight>

=={{header|GDScript}}==
{{works with|Godot|4.0.1}}
{{trans|11l}}

<syntaxhighlight lang="gdscript">
extends MainLoop


func _process(_delta: float) -> bool:
for i in range(1,11):
if i % 5 == 0:
print(i)
continue
printraw(i, ", ")

return true # Exit
</syntaxhighlight>



=={{header|GML}}==
=={{header|GML}}==
<lang GML>for(i = 1; i <= 10; i += 1)
<syntaxhighlight lang="gml">for(i = 1; i <= 10; i += 1)
{
{
show_message(string(i))
show_message(string(i))
Line 1,035: Line 1,192:
if(i <= 10)
if(i <= 10)
continue
continue
}</lang>
}</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 1,051: Line 1,208:
fmt.Printf(", ")
fmt.Printf(", ")
}
}
}</lang>
}</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 1,059: Line 1,216:


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>for (i in 1..10) {
<syntaxhighlight lang="groovy">for (i in 1..10) {
print i
print i
if (i % 5 == 0) {
if (i % 5 == 0) {
Line 1,066: Line 1,223:
}
}
print ', '
print ', '
}</lang>
}</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 1,072: Line 1,229:
The below code uses a guard (| symbol) to compose functions differently for the two alternative output paths, instead of using continue like in an imperative language.
The below code uses a guard (| symbol) to compose functions differently for the two alternative output paths, instead of using continue like in an imperative language.


<lang haskell>import Control.Monad (forM)
<syntaxhighlight lang="haskell">import Control.Monad (forM)
main = forM [1..10] out
main = forM [1..10] out
where
where
out x | x `mod` 5 == 0 = print x
out x | x `mod` 5 == 0 = print x
| otherwise = (putStr . (++", ") . show) x</lang>
| otherwise = (putStr . (++", ") . show) x</syntaxhighlight>


=={{header|Haxe}}==
=={{header|Haxe}}==
<lang haxe>for (i in 1...11) {
<syntaxhighlight lang="haxe">for (i in 1...11) {
Sys.print(i);
Sys.print(i);
if (i % 5 == 0) {
if (i % 5 == 0) {
Line 1,086: Line 1,243:
}
}
Sys.print(', ');
Sys.print(', ');
}</lang>
}</syntaxhighlight>


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang hicest>DO i = 1, 10
<syntaxhighlight lang="hicest">DO i = 1, 10
IF( MOD(i, 5) == 1 ) THEN
IF( MOD(i, 5) == 1 ) THEN
WRITE(Format="i3") i
WRITE(Format="i3") i
Line 1,095: Line 1,252:
WRITE(APPend, Format=" ',', i3 ") i
WRITE(APPend, Format=" ',', i3 ") i
ENDIF
ENDIF
ENDDO </lang>
ENDDO </syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
The following code demonstrates the use of 'next' (the reserved word for 'continue'):
The following code demonstrates the use of 'next' (the reserved word for 'continue'):
<lang Icon>procedure main()
<syntaxhighlight lang="icon">procedure main()
every writes(x := 1 to 10) do {
every writes(x := 1 to 10) do {
if x % 5 = 0 then {
if x % 5 = 0 then {
Line 1,107: Line 1,264:
writes(", ")
writes(", ")
}
}
end</lang>
end</syntaxhighlight>
However, the output sequence can be written without 'next' and far more succinctly as:
However, the output sequence can be written without 'next' and far more succinctly as:
<lang Icon>every writes(x := 1 to 10, if x % 5 = 0 then "\n" else ", ")</lang>
<syntaxhighlight lang="icon">every writes(x := 1 to 10, if x % 5 = 0 then "\n" else ", ")</syntaxhighlight>


=={{header|Io}}==
=={{header|Io}}==
<lang io>for(i,1,10,
<syntaxhighlight lang="io">for(i,1,10,
write(i)
write(i)
if(i%5 == 0, writeln() ; continue)
if(i%5 == 0, writeln() ; continue)
write(" ,")
write(" ,")
)</lang>
)</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
Line 1,122: Line 1,279:
For example, one could satisfy this task this way:
For example, one could satisfy this task this way:


<lang j>_2}."1'lq<, >'8!:2>:i.2 5</lang>
<syntaxhighlight lang="j">_2}."1'lq<, >'8!:2>:i.2 5</syntaxhighlight>


J does support loops for those times they can't be avoided
J does support loops for those times they can't be avoided
(just like many languages support gotos for those time they can't be avoided).
(just like many languages support gotos for those time they can't be avoided).
<lang j>3 : 0 ] 10
<syntaxhighlight lang="j">3 : 0 ] 10
z=.''
z=.''
for_i. 1 + i.y do.
for_i. 1 + i.y do.
Line 1,140: Line 1,297:
end.
end.
i.0 0
i.0 0
)</lang>
)</syntaxhighlight>


Though it's rare to see J code like this.
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}}==
=={{header|Java}}==
<lang java>for(int i = 1;i <= 10; i++){
<syntaxhighlight lang="java">for(int i = 1;i <= 10; i++){
System.out.print(i);
System.out.print(i);
if(i % 5 == 0){
if(i % 5 == 0){
Line 1,152: Line 1,322:
}
}
System.out.print(", ");
System.out.print(", ");
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
Using the <code>print()</code> function from [[Rhino]] or [[SpiderMonkey]].
Using the <code>print()</code> function from [[Rhino]] or [[SpiderMonkey]].
<lang javascript>var output = "";
<syntaxhighlight lang="javascript">var output = "";
for (var i = 1; i <= 10; i++) {
for (var i = 1; i <= 10; i++) {
output += i;
output += i;
Line 1,165: Line 1,335:
}
}
output += ", ";
output += ", ";
}</lang>
}</syntaxhighlight>




Line 1,172: Line 1,342:
For example:
For example:


<lang JavaScript>function rng(n) {
<syntaxhighlight lang="javascript">function rng(n) {
return n ? rng(n - 1).concat(n) : [];
return n ? rng(n - 1).concat(n) : [];
}
}
Line 1,182: Line 1,352:
}, ''
}, ''
)
)
);</lang>
);</syntaxhighlight>


Output:
Output:
<lang JavaScript>1, 2, 3, 4, 5
<syntaxhighlight lang="javascript">1, 2, 3, 4, 5
6, 7, 8, 9, 10
6, 7, 8, 9, 10
</syntaxhighlight>
</lang>


=={{header|jq}}==
=={{header|jq}}==
jq does not have a "continue" statement.
jq does not have a "continue" statement.
In jq 1.4, the simplest way to accomplish the given task is probably as follows:
In jq 1.4, the simplest way to accomplish the given task is probably as follows:
<lang jq>reduce range(1;11) as $i
<syntaxhighlight lang="jq">reduce range(1;11) as $i
(""; . + "\($i)" + (if $i % 5 == 0 then "\n" else ", " end))</lang>
(""; . + "\($i)" + (if $i % 5 == 0 then "\n" else ", " end))</syntaxhighlight>


=={{header|Jsish}}==
=={{header|Jsish}}==
<lang javascript>/* Loop/continue in jsish */
<syntaxhighlight lang="javascript">/* Loop/continue in jsish */
for (var i = 1; i <= 10; i++) {
for (var i = 1; i <= 10; i++) {
printf("%d", i);
printf("%d", i);
Line 1,204: Line 1,374:
}
}
printf(", ");
printf(", ");
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,212: Line 1,382:


=={{header|Julia}}==
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
for i in 1:10
for i in 1:10
print(i)
print(i)
Line 1,221: Line 1,391:
print(", ")
print(", ")
end
end
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,230: Line 1,400:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.1.2
<syntaxhighlight lang="scala">// version 1.1.2


fun main(args: Array<String>) {
fun main(args: Array<String>) {
Line 1,240: Line 1,410:
print("$i, ")
print("$i, ")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,249: Line 1,419:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang="scheme">
{def loops_continue
{def loops_continue
{lambda {:i}
{lambda {:i}
Line 1,262: Line 1,432:
-> 0, 1, 2, 3, 4, 5,
-> 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10. (end of loop)
6, 7, 8, 9, 10. (end of loop)
</syntaxhighlight>
</lang>

=={{header|Lang}}==
<syntaxhighlight lang="lang">
$i = 0
while($i < 10) {
$i += 1
if($i % 5 === 0) {
fn.println($i)
con.continue
}
fn.print($i\,\s)
}
</syntaxhighlight>

{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>


=={{header|langur}}==
=={{header|langur}}==
<syntaxhighlight lang="langur">for .i of 10 {
{{works with|langur|0.8.1}}
<lang langur>for .i of 10 {
write .i
write .i
if .i div 5 { writeln(); next }
if .i div 5 { writeln(); next }
write ", "
write ", "
}</lang>
}</syntaxhighlight>


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>loop(10) => {^
<syntaxhighlight lang="lasso">loop(10) => {^
loop_count
loop_count
loop_count % 5 ? ', ' | '\r'
loop_count % 5 ? ', ' | '\r'
loop_count < 100 ? loop_continue
loop_count < 100 ? loop_continue
'Hello, World!' // never gets executed
'Hello, World!' // never gets executed
^}</lang>
^}</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}}==
=={{header|Lingo}}==
<lang lingo>str = ""
<syntaxhighlight lang="lingo">str = ""
repeat with i = 1 to 10
repeat with i = 1 to 10
put i after str
put i after str
Line 1,290: Line 1,501:
put ", " after str
put ", " after str
end repeat
end repeat
put str</lang>
put str</syntaxhighlight>


=={{header|Lisaac}}==
=={{header|Lisaac}}==
<lang Lisaac>1.to 10 do { i : INTEGER;
<syntaxhighlight lang="lisaac">1.to 10 do { i : INTEGER;
i.print;
i.print;
(i % 5 = 0).if { '\n'.print; } else { ','.print; };
(i % 5 = 0).if { '\n'.print; } else { ','.print; };
};</lang>
};</syntaxhighlight>


=={{header|LiveCode}}==
=={{header|LiveCode}}==
<lang LiveCode>repeat with n = 1 to 10
<syntaxhighlight lang="livecode">repeat with n = 1 to 10
put n
put n
if n is 5 then put return
if n is 5 then put return
if n < 10 and n is not 5 then put ","
if n < 10 and n is not 5 then put ","
end repeat</lang>
end repeat</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>for i = 1, 10 do
<syntaxhighlight lang="lua">for i = 1, 10 do
io.write( i )
io.write( i )
if i % 5 == 0 then
if i % 5 == 0 then
Line 1,313: Line 1,524:
io.write( ", " )
io.write( ", " )
end
end
end</lang>
end</syntaxhighlight>
or
<syntaxhighlight lang="lua">for i = 1, 10 do
io.write( i )
if i % 5 == 0 then
io.write( "\n" )
goto continue
end
io.write( ", " )
::continue::
end</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
Module Checkit {
\\ A For {} loop
\\ A For {} loop
Line 1,353: Line 1,574:
}
}
Checkit
Checkit
</syntaxhighlight>
</lang>


=={{header|Maple}}==
=={{header|Maple}}==
<lang Maple>for i from 1 to 10 do
<syntaxhighlight lang="maple">for i from 1 to 10 do
printf( "%d", i );
printf( "%d", i );
if irem( i, 5 ) = 0 then
if irem( i, 5 ) = 0 then
Line 1,363: Line 1,584:
end if;
end if;
printf( ", " )
printf( ", " )
end do:</lang>
end do:</syntaxhighlight>


This can also be done as follows, but without the use of "next".
This can also be done as follows, but without the use of "next".
<lang Maple>for i to 10 do
<syntaxhighlight lang="maple">for i to 10 do
printf( "%d%s", i, `if`( irem( i, 5 ) = 0, "\n", ", " ) )
printf( "%d%s", i, `if`( irem( i, 5 ) = 0, "\n", ", " ) )
end do:</lang>
end do:</syntaxhighlight>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>tmp = "";
<syntaxhighlight lang="mathematica">tmp = "";
For[i = 1, i <= 10, i++,
For[i = 1, i <= 10, i++,
tmp = tmp <> ToString[i];
tmp = tmp <> ToString[i];
Line 1,380: Line 1,601:
];
];
];
];
Print[tmp]</lang>
Print[tmp]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
Line 1,386: Line 1,607:
Loops are considered slow in Matlab and Octave,
Loops are considered slow in Matlab and Octave,
it is preferable to vectorize the code.
it is preferable to vectorize the code.
<lang Matlab>disp([1:5; 6:10])</lang>
<syntaxhighlight lang="matlab">disp([1:5; 6:10])</syntaxhighlight>
or
or
<lang Matlab>disp(reshape([1:10],5,2)')</lang>
<syntaxhighlight lang="matlab">disp(reshape([1:10],5,2)')</syntaxhighlight>


A non-vectorized version of the code is shown below in Octave
A non-vectorized version of the code is shown below in Octave


<lang Matlab>for i = 1:10
<syntaxhighlight lang="matlab">for i = 1:10
printf(' %2d', i);
printf(' %2d', i);
if ( mod(i, 5) == 0 )
if ( mod(i, 5) == 0 )
Line 1,398: Line 1,619:
continue
continue
end
end
end</lang>
end</syntaxhighlight>


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>/* There is no "continue" in Maxima, the easiest is using a "if" instead */
<syntaxhighlight lang="maxima">/* There is no "continue" in Maxima, the easiest is using a "if" instead */
block(
block(
[s: ""],
[s: ""],
Line 1,413: Line 1,634:
)
)
)
)
)$</lang>
)$</syntaxhighlight>
Using sprint and newline
<syntaxhighlight lang="maxima">
for n:1 thru 10 do (
sprint(n),
if n=5 then newline())$
</syntaxhighlight>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
<lang maxscript>for i in 1 to 10 do
<syntaxhighlight lang="maxscript">for i in 1 to 10 do
(
(
format "%" i
format "%" i
Line 1,425: Line 1,652:
) continue
) continue
format ", "
format ", "
)</lang>
)</syntaxhighlight>
<nowiki>Insert non-formatted text here</nowiki>
<nowiki>Insert non-formatted text here</nowiki>


Line 1,432: Line 1,659:
As the [[Loop/Continue#Ada|Ada solution]], we can complete the task just with conditional.
As the [[Loop/Continue#Ada|Ada solution]], we can complete the task just with conditional.


<lang metafont>string s; s := "";
<syntaxhighlight lang="metafont">string s; s := "";
for i = 1 step 1 until 10:
for i = 1 step 1 until 10:
if i mod 5 = 0:
if i mod 5 = 0:
Line 1,440: Line 1,667:
fi; endfor
fi; endfor
message s;
message s;
end</lang>
end</syntaxhighlight>


Since <tt>message</tt> append always a newline at the end,
Since <tt>message</tt> append always a newline at the end,
Line 1,448: Line 1,675:
'''Note''': <tt>mod</tt> is not a built in; like TeX, "bare Metafont" is rather primitive, and normally a set of basic macros is preloaded to make it more usable; in particular <tt>mod</tt> is defined as
'''Note''': <tt>mod</tt> is not a built in; like TeX, "bare Metafont" is rather primitive, and normally a set of basic macros is preloaded to make it more usable; in particular <tt>mod</tt> is defined as


<lang metafont>primarydef x mod y = (x-y*floor(x/y)) enddef;</lang>
<syntaxhighlight lang="metafont">primarydef x mod y = (x-y*floor(x/y)) enddef;</syntaxhighlight>


=={{header|Modula-3}}==
=={{header|Modula-3}}==
Line 1,458: Line 1,685:


Module code and imports are omitted.
Module code and imports are omitted.
<lang modula3>FOR i := 1 TO 10 DO
<syntaxhighlight lang="modula3">FOR i := 1 TO 10 DO
IO.PutInt(i);
IO.PutInt(i);
IF i MOD 5 = 0 THEN
IF i MOD 5 = 0 THEN
Line 1,465: Line 1,692:
END;
END;
IO.Put(", ");
IO.Put(", ");
END;</lang>
END;</syntaxhighlight>


=={{header|MOO}}==
=={{header|MOO}}==
<lang moo>s = "";
<syntaxhighlight lang="moo">s = "";
for i in [1..10]
for i in [1..10]
s += tostr(i);
s += tostr(i);
Line 1,477: Line 1,704:
endif
endif
s += ", ";
s += ", ";
endfor</lang>
endfor</syntaxhighlight>


=={{header|Neko}}==
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
Loops/Continue in Neko
Loops/Continue in Neko
Tectonics:
Tectonics:
Line 1,499: Line 1,726:
}
}
$print(", ");
$print(", ");
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,509: Line 1,736:
=={{header|Nemerle}}==
=={{header|Nemerle}}==
{{trans|C#}}
{{trans|C#}}
<lang Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.Console;
using System.Console;
using Nemerle.Imperative;
using Nemerle.Imperative;
Line 1,524: Line 1,751:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
options replace format comments java crossref savelog symbols nobinary


Line 1,543: Line 1,770:
end i_
end i_
</syntaxhighlight>
</lang>


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang NewLISP>(for (i 1 10)
<syntaxhighlight lang="newlisp">(for (i 1 10)
(print i)
(print i)
(if (= 0 (% i 5))
(if (= 0 (% i 5))
(println)
(println)
(print ", ")))</lang>
(print ", ")))</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Python}}
{{trans|Python}}
<lang nim>for i in 1..10:
<syntaxhighlight lang="nim">for i in 1..10:
if i mod 5 == 0:
if i mod 5 == 0:
echo i
echo i
continue
continue
stdout.write i, ", "</lang>
stdout.write i, ", "</syntaxhighlight>


=={{header|NS-HUBASIC}}==
=={{header|NS-HUBASIC}}==
<lang NS-HUBASIC>10 FOR I=1 TO 10
<syntaxhighlight lang="ns-hubasic">10 FOR I=1 TO 10
20 PRINT I;
20 PRINT I;
30 IF I-I/5*5=0 THEN PRINT :GOTO 50"CONTINUE
30 IF I-I/5*5=0 THEN PRINT :GOTO 50"CONTINUE
40 PRINT ",";
40 PRINT ",";
50 NEXT</lang>
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}}==
=={{header|Objeck}}==
<lang objeck>class Continue {
<syntaxhighlight lang="objeck">class Continue {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
for(i := 1; i <= 10; i += 1;) {
for(i := 1; i <= 10; i += 1;) {
Line 1,578: Line 1,817:
};
};
}
}
}</lang>
}</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
There is no continue statement for for loops in OCaml,
There is no continue statement for for loops in OCaml,
but it is possible to achieve the same effect with an exception.
but it is possible to achieve the same effect with an exception.
<lang ocaml># for i = 1 to 10 do
<syntaxhighlight lang="ocaml"># for i = 1 to 10 do
try
try
print_int i;
print_int i;
Line 1,594: Line 1,833:
1, 2, 3, 4, 5
1, 2, 3, 4, 5
6, 7, 8, 9, 10
6, 7, 8, 9, 10
- : unit = ()</lang>
- : unit = ()</syntaxhighlight>
Though even if the continue statement does not exist,
Though even if the continue statement does not exist,
it is possible to add it with camlp4.
it is possible to add it with camlp4.


=={{header|Octave}}==
=={{header|Octave}}==
<lang octave>v = "";
<syntaxhighlight lang="octave">v = "";
for i = 1:10
for i = 1:10
v = sprintf("%s%d", v, i);
v = sprintf("%s%d", v, i);
Line 1,608: Line 1,847:
endif
endif
v = sprintf("%s, ", v);
v = sprintf("%s, ", v);
endfor</lang>
endfor</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>: loopCont
<syntaxhighlight lang="oforth">: loopCont
| i |
| i |
10 loop: i [
10 loop: i [
i dup print 5 mod ifZero: [ printcr continue ]
i dup print 5 mod ifZero: [ printcr continue ]
"," .
"," .
] ;</lang>
] ;</syntaxhighlight>

=={{header|Ol}}==
We use continuation to break the execution of the inner body.
<syntaxhighlight lang="scheme">
(let loop ((i 1))
(when (less? i 11)
(call/cc (lambda (continue)
(display i)
(when (zero? (mod i 5))
(print)
(continue #f))
(display ", ")))
(loop (+ i 1))))
</syntaxhighlight>
{{Out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>


=={{header|Oz}}==
=={{header|Oz}}==
By using the "continue" feature of the for-loop, we bind C to a nullary procedure which, when invoked, immediately goes on to the next iteration of the loop.
By using the "continue" feature of the for-loop, we bind C to a nullary procedure which, when invoked, immediately goes on to the next iteration of the loop.
<lang oz>for I in 1..10 continue:C do
<syntaxhighlight lang="oz">for I in 1..10 continue:C do
{System.print I}
{System.print I}
if I mod 5 == 0 then
if I mod 5 == 0 then
Line 1,628: Line 1,886:
end
end
{System.printInfo ", "}
{System.printInfo ", "}
end</lang>
end</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>for(n=1,10,
<syntaxhighlight lang="parigp">for(n=1,10,
print1(n);
print1(n);
if(n%5 == 0, print();continue);
if(n%5 == 0, print();continue);
print1(", ")
print1(", ")
)</lang>
)</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 1,641: Line 1,899:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>foreach (1..10) {
<syntaxhighlight lang="perl">foreach (1..10) {
print $_;
print $_;
if ($_ % 5 == 0) {
if ($_ % 5 == 0) {
Line 1,648: Line 1,906:
}
}
print ', ';
print ', ';
}</lang>
}</syntaxhighlight>


It is also possible to use a goto statement
It is also possible to use a goto statement
to jump over the iterative code section for a particular loop:
to jump over the iterative code section for a particular loop:


<lang perl>foreach (1..10) {
<syntaxhighlight lang="perl">foreach (1..10) {
print $_;
print $_;
if ($_ % 5 == 0) {
if ($_ % 5 == 0) {
Line 1,661: Line 1,919:
print ', ';
print ', ';
MYLABEL:
MYLABEL:
}</lang>
}</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/basics}}
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
Line 1,674: Line 1,933:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">", "</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
The following works just as well
<pre>
<!--<lang Phix>-->
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
The following works just as well, with identical output
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
Line 1,685: Line 1,950:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHP}}==
=={{header|PHP}}==
<lang php>for ($i = 1; $i <= 10; $i++) {
<syntaxhighlight lang="php">for ($i = 1; $i <= 10; $i++) {
echo $i;
echo $i;
if ($i % 5 == 0) {
if ($i % 5 == 0) {
Line 1,695: Line 1,960:
}
}
echo ', ';
echo ', ';
}</lang>
}</syntaxhighlight>

=={{header|Picat}}==
Picat doesn't have a continue statement. So I just use a conditional that ends the body of the predicate.

{{trans|Prolog}}
{{works with|Picat}}
<syntaxhighlight lang="picat">
main =>
foreach (I in 1..10)
printf("%d", I),
if (I mod 5 == 0) then
nl
else
printf(", ")
end,
end.
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
PicoLisp doesn't have an explicit 'continue' functionality.
PicoLisp doesn't have an explicit 'continue' functionality.
It can always be emulated with a conditional expression.
It can always be emulated with a conditional expression.
<lang PicoLisp>(for I 10
<syntaxhighlight lang="picolisp">(for I 10
(print I)
(print I)
(if (=0 (% I 5))
(if (=0 (% I 5))
(prinl)
(prinl)
(prin ", ") ) )</lang>
(prin ", ") ) )</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>int main(){
<syntaxhighlight lang="pike">int main(){
for(int i = 1; i <= 10; i++){
for(int i = 1; i <= 10; i++){
write(sprintf("%d",i));
write(sprintf("%d",i));
Line 1,716: Line 2,003:
write(", ");
write(", ");
}
}
}</lang>
}</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>loop:
<syntaxhighlight lang="pli">loop:
do i = 1 to 10;
do i = 1 to 10;
put edit (i) (f(3));
put edit (i) (f(3));
if mod(i,5) = 0 then do; put skip; iterate loop; end;
if mod(i,5) = 0 then do; put skip; iterate loop; end;
put edit (', ') (a);
put edit (', ') (a);
end;</lang>
end;</syntaxhighlight>


=={{header|Plain English}}==
=={{header|Plain English}}==
In Plain English, continue is spelled <code>repeat</code> and is the only way to specify an end of a loop.
In Plain English, continue is spelled <code>repeat</code> and is the only way to specify an end of a loop.
<lang plainenglish>To run:
<syntaxhighlight lang="plainenglish">To run:
Start up.
Start up.
Demonstrate continue.
Demonstrate continue.
Line 1,740: Line 2,027:
If the counter is evenly divisible by 5, write "" on the console; repeat.
If the counter is evenly divisible by 5, write "" on the console; repeat.
Write ", " on the console without advancing.
Write ", " on the console without advancing.
Repeat.</lang>
Repeat.</syntaxhighlight>


=={{header|Pop11}}==
=={{header|Pop11}}==
<lang pop11>lvars i;
<syntaxhighlight lang="pop11">lvars i;
for i from 1 to 10 do
for i from 1 to 10 do
printf(i, '%p');
printf(i, '%p');
Line 1,751: Line 2,038:
endif;
endif;
printf(', ')
printf(', ')
endfor;</lang>
endfor;</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
{{trans|C}}
{{trans|C}}
<lang powershell>for ($i = 1; $i -le 10; $i++) {
<syntaxhighlight lang="powershell">for ($i = 1; $i -le 10; $i++) {
Write-Host -NoNewline $i
Write-Host -NoNewline $i
if ($i % 5 -eq 0) {
if ($i % 5 -eq 0) {
Line 1,762: Line 2,049:
}
}
Write-Host -NoNewline ", "
Write-Host -NoNewline ", "
}</lang>
}</syntaxhighlight>

=={{header|Prolog}}==
Prolog doesn't have a continue statement. So I just use a conditional that ends the body of the predicate.

{{works with|GNU Prolog}}
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">
:- initialization(main).

print_list(Min, Max) :-
Min < Max,
write(Min),
Min1 is Min + 1,
(
Min mod 5 =:= 0
-> nl
; write(',')
),
print_list(Min1, Max).

print_list(Max, Max) :-
write(Max),
nl.

main :-
print_list(1, 10).
</syntaxhighlight>
{{out}}
<pre>
1,2,3,4,5
6,7,8,9,10
</pre>


=={{header|Python}}==
=={{header|Python}}==
<lang python>for i in xrange(1,11):
<syntaxhighlight lang="python">for i in range(1, 11):
if i % 5 == 0:
if i % 5 == 0:
print i
print(i)
continue
continue
print i, ",",</lang>
print(i, end=', ')</syntaxhighlight>


=={{header|Quackery}}==
=={{header|Quackery}}==
<lang quackery>10 times
<syntaxhighlight lang="quackery">10 times
[ i^ 1+ dup echo
[ i^ 1+ dup echo
5 mod 0 = iff
5 mod 0 = iff
cr done
cr done
say ", " ]</lang>
say ", " ]</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
{{trans|C++}}
{{trans|C++}}
<lang R>for(i in 1:10)
<syntaxhighlight lang="r">for(i in 1:10)
{
{
cat(i)
cat(i)
Line 1,789: Line 2,108:
}
}
cat(", ")
cat(", ")
}</lang>
}</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 1,796: Line 2,115:
but an explicit <tt>continue</tt> construct is rarely used:
but an explicit <tt>continue</tt> construct is rarely used:


<lang racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket


Line 1,811: Line 2,130:
(printf "~a~n" i)))
(printf "~a~n" i)))
(printf "~a, " i))
(printf "~a, " i))
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
Line 1,817: Line 2,136:
{{trans|Perl}}
{{trans|Perl}}
{{works with|Rakudo Star|2010.08}}
{{works with|Rakudo Star|2010.08}}
<lang perl6>for 1 .. 10 {
<syntaxhighlight lang="raku" line>for 1 .. 10 {
.print;
.print;
if $_ %% 5 {
if $_ %% 5 {
Line 1,824: Line 2,143:
}
}
print ', ';
print ', ';
}</lang>
}</syntaxhighlight>


or without using a loop:
or without using a loop:


<lang perl6>$_.join(", ").say for [1..5], [6..10];</lang>
<syntaxhighlight lang="raku" line>$_.join(", ").say for [1..5], [6..10];</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<lang REBOL>REBOL [
<syntaxhighlight lang="rebol">REBOL [
Title: "Loop/Continue"
Title: "Loop/Continue"
URL: http://rosettacode.org/wiki/Loop/Continue
URL: http://rosettacode.org/wiki/Loop/Continue
Line 1,850: Line 2,169:
prin ", "
prin ", "
]
]
]</lang>
]</syntaxhighlight>


{{Out}}
{{Out}}
Line 1,862: Line 2,181:


=={{header|Red}}==
=={{header|Red}}==
<lang Red>repeat i 10 [
<syntaxhighlight lang="red">repeat i 10 [
prin i
prin i
if i = 10 [break]
if i = 10 [break]
Line 1,868: Line 2,187:
]
]
1,2,3,4,5
1,2,3,4,5
6,7,8,9,10</lang>
6,7,8,9,10</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
===version 1===
===version 1===
(This program could be simpler by using a &nbsp; '''then/else''' &nbsp; construct, but an &nbsp; '''iterate''' &nbsp; was used to conform to the task.)
(This program could be simpler by using a &nbsp; '''then/else''' &nbsp; construct, but an &nbsp; '''iterate''' &nbsp; was used to conform to the task.)
<lang rexx>/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */
<syntaxhighlight lang="rexx">/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */


do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */
do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */
Line 1,883: Line 2,202:
say /*force REXX to display on next line. */
say /*force REXX to display on next line. */
end /*j*/
end /*j*/
/*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</syntaxhighlight>
Program note: &nbsp; the comma (<big><b>,</b></big>) immediately after the &nbsp; '''charout''' &nbsp; BIF indicates to use the terminal output stream.
Program note: &nbsp; the comma (<big><b>,</b></big>) immediately after the &nbsp; '''charout''' &nbsp; BIF indicates to use the terminal output stream.


Line 1,893: Line 2,212:


===version 2===
===version 2===
<lang rexx>/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */
<syntaxhighlight lang="rexx">/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */
$= /*nullify the variable used for display*/
$= /*nullify the variable used for display*/
do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */
do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */
Line 1,900: Line 2,219:
if j==5 then $= /*start the display line over again. */
if j==5 then $= /*start the display line over again. */
end /*j*/
end /*j*/
/*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</syntaxhighlight>
'''output''' &nbsp; is the same as the 1<sup>st</sup> REXX version. <br><br>
'''output''' &nbsp; is the same as the 1<sup>st</sup> REXX version. <br><br>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
for i = 1 TO 10
for i = 1 TO 10
see i
see i
Line 1,913: Line 2,232:
see ", "
see ", "
next
next
</syntaxhighlight>
</lang>

=={{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}}==
=={{header|Ruby}}==
<lang ruby>for i in 1..10 do
<syntaxhighlight lang="ruby">for i in 1..10 do
print i
print i
if i % 5 == 0 then
if i % 5 == 0 then
Line 1,923: Line 2,251:
end
end
print ', '
print ', '
end</lang>
end</syntaxhighlight>
The "for" look could be written like this:
The "for" look could be written like this:
<lang ruby>(1..10).each do |i| ...
<syntaxhighlight lang="ruby">(1..10).each do |i| ...
1.upto(10) do |i| ...
1.upto(10) do |i| ...
10.times do |n| i=n+1; ...</lang>
10.times do |n| i=n+1; ...</syntaxhighlight>
Without meeting the criteria (showing loop continuation), this task could be written as:
Without meeting the criteria (showing loop continuation), this task could be written as:
<lang ruby>(1..10).each_slice(5){|ar| puts ar.join(", ")}</lang>
<syntaxhighlight lang="ruby">(1..10).each_slice(5){|ar| puts ar.join(", ")}</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>fn main() {
<syntaxhighlight lang="rust">fn main() {
for i in 1..=10 {
for i in 1..=10 {
print!("{}", i);
print!("{}", i);
Line 1,941: Line 2,269:
print!(", ");
print!(", ");
}
}
}</lang>
}</syntaxhighlight>


=={{header|Salmon}}==
=={{header|Salmon}}==
<lang Salmon>iterate (x; [1...10])
<syntaxhighlight lang="salmon">iterate (x; [1...10])
{
{
print(x);
print(x);
Line 1,953: Line 2,281:
};
};
print(", ");
print(", ");
};</lang>
};</syntaxhighlight>


=={{header|Sather}}==
=={{header|Sather}}==
There's no <code>continue!</code> in Sather. The code solve the task without forcing a new iteration.
There's no <code>continue!</code> in Sather. The code solve the task without forcing a new iteration.
<lang sather>class MAIN is
<syntaxhighlight lang="sather">class MAIN is
main is
main is
i:INT;
i:INT;
Line 1,969: Line 2,297:
end;
end;
end;
end;
end;</lang>
end;</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
Line 1,976: Line 2,304:


===The intuitive way===
===The intuitive way===
<lang scala>for (i <- 1 to 10) {
<syntaxhighlight lang="scala">for (i <- 1 to 10) {
print(i)
print(i)
if (i % 5 == 0) println() else print(", ")
if (i % 5 == 0) println() else print(", ")
}</lang>
}</syntaxhighlight>


===Functional solution===
===Functional solution===
Line 1,988: Line 2,316:
#The map makes for both elements in the List a conversion to a comma separated String, yielding a List of two Strings.
#The map makes for both elements in the List a conversion to a comma separated String, yielding a List of two Strings.
#Both comma separated strings will be separated by an EOL
#Both comma separated strings will be separated by an EOL
<lang scala> val a = (1 to 10 /*1.*/ ).toList.splitAt(5) //2.
<syntaxhighlight lang="scala"> val a = (1 to 10 /*1.*/ ).toList.splitAt(5) //2.
println(List(a._1, a._2) /*3.*/ .map(_.mkString(", ") /*4.*/ ).mkString("\n") /*5.*/ )</lang>
println(List(a._1, a._2) /*3.*/ .map(_.mkString(", ") /*4.*/ ).mkString("\n") /*5.*/ )</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
For R7RS Scheme. In this functional solution, there is no "continue". Instead, the "loop" function is directly called in the tail end (this is [[Recursion|Tail Recursion]]).
<lang scheme>(define (loop i)
<syntaxhighlight lang="scheme">(import (scheme base)
(if (> i 10) 'done
(begin
(scheme write))

(display i)
(define (loop-fn start end)
(cond ((zero? (modulo i 5))
(newline) (loop (+ 1 i)))
(define (loop i)
(else (display ", ")
(if (> i end) #f
(begin
(loop (+ 1 i)))))))</lang>
(display i)
(cond ((zero? (modulo i 5))
(newline) (loop (+ 1 i)))
(else
(display ", ")
(loop (+ 1 i)))))))
(loop start))

(loop-fn 1 10)</syntaxhighlight>


=={{header|Scilab}}==
=={{header|Scilab}}==
{{works with|Scilab|5.5.1}}
{{works with|Scilab|5.5.1}}
<lang>for i=1:10
<syntaxhighlight lang="text">for i=1:10
printf("%2d ",i)
printf("%2d ",i)
if modulo(i,5)~=0 then
if modulo(i,5)~=0 then
Line 2,010: Line 2,347:
end
end
printf("\n")
printf("\n")
end </lang>
end </syntaxhighlight>
{{out}}
{{out}}
<pre> 1 , 2 , 3 , 4 , 5
<pre> 1 , 2 , 3 , 4 , 5
Line 2,016: Line 2,353:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>for i in (1..10) {
<syntaxhighlight lang="ruby">for i in (1..10) {
print i
print i
if (i %% 5) {
if (i %% 5) {
Line 2,023: Line 2,360:
}
}
print ', '
print ', '
}</lang>
}</syntaxhighlight>


=={{header|Simula}}==
=={{header|Simula}}==
{{works with|SIMULA-67}}
{{works with|SIMULA-67}}
<lang simula>! Loops/Continue - simula67 - 07/03/2017;
<syntaxhighlight lang="simula">! Loops/Continue - simula67 - 07/03/2017;
begin
begin
integer i;
integer i;
Line 2,039: Line 2,376:
loop:
loop:
end
end
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,048: Line 2,385:
=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
{{works with|Pharo}} {{works with|Smalltalk/X}} actually works with all dialects &sup1;
{{works with|Pharo}} {{works with|Smalltalk/X}} actually works with all dialects &sup1;
<syntaxhighlight lang="smalltalk">
<lang Smalltalk>
1 to: 10 do: [ :i |
1 to: 10 do: [ :i |
[ :continue |
[ :continue |
Line 2,059: Line 2,396:
] valueWithExit.
] valueWithExit.
]
]
</syntaxhighlight>
</lang>
&sup1; if valueWithExit is not present in the Block class, it can be added as:
&sup1; if valueWithExit is not present in the Block class, it can be added as:
<lang Smalltalk>valueWithExit
<syntaxhighlight lang="smalltalk">valueWithExit
^ self value:[^ nil]</lang>
^ 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}}==
=={{header|Spin}}==
Line 2,069: Line 2,441:
{{works with|HomeSpun}}
{{works with|HomeSpun}}
{{works with|OpenSpin}}
{{works with|OpenSpin}}
<syntaxhighlight lang="spin">con
<lang Spin>con
_clkmode = xtal1 + pll16x
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
_clkfreq = 80_000_000
Line 2,088: Line 2,460:
waitcnt(_clkfreq + cnt)
waitcnt(_clkfreq + cnt)
ser.stop
ser.stop
cogstop(0)</lang>
cogstop(0)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,096: Line 2,468:


=={{header|SPL}}==
=={{header|SPL}}==
<lang spl>> n, 1..10
<syntaxhighlight lang="spl">> n, 1..10
s += n
s += n
? n%5, s += ", "
? n%5, s += ", "
Line 2,102: Line 2,474:
#.output(s)
#.output(s)
s = ""
s = ""
<</lang>
<</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,112: Line 2,484:
{{works with|Db2 LUW}} version 9.7 or higher.
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
With SQL PL:
<lang sql pl>
<syntaxhighlight lang="sql pl">
--#SET TERMINATOR @
--#SET TERMINATOR @


Line 2,130: Line 2,502:
END WHILE Loop;
END WHILE Loop;
END @
END @
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 2,145: Line 2,517:
See '''[https://www.stata.com/help.cgi?continue continue]''' in Stata help. Notice that the _continue option of '''[https://www.stata.com/help.cgi?display display]''' has another purpose: it suppresses the automatic newline at the end of the display command.
See '''[https://www.stata.com/help.cgi?continue continue]''' in Stata help. Notice that the _continue option of '''[https://www.stata.com/help.cgi?display display]''' has another purpose: it suppresses the automatic newline at the end of the display command.


<lang stata>forvalues n=1/10 {
<syntaxhighlight lang="stata">forvalues n=1/10 {
display `n' _continue
display `n' _continue
if mod(`n',5)==0 {
if mod(`n',5)==0 {
Line 2,152: Line 2,524:
}
}
display ", " _continue
display ", " _continue
}</lang>
}</syntaxhighlight>


=={{header|Suneido}}==
=={{header|Suneido}}==
<lang Suneido>ob = Object()
<syntaxhighlight lang="suneido">ob = Object()
for (i = 1; i <= 10; ++i)
for (i = 1; i <= 10; ++i)
{
{
Line 2,165: Line 2,537:
}
}
}
}
Print(ob.Join(','))</lang>
Print(ob.Join(','))</syntaxhighlight>


{{Out}}
{{Out}}
<lang Suneido>1,2,3,4,5
<syntaxhighlight lang="suneido">1,2,3,4,5
6,7,8,9,10
6,7,8,9,10
ok</lang>
ok</syntaxhighlight>


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>for i in 1...10 {
<syntaxhighlight lang="swift">for i in 1...10 {
print(i, terminator: "")
print(i, terminator: "")
if i % 5 == 0 {
if i % 5 == 0 {
Line 2,180: Line 2,552:
}
}
print(", ", terminator: "")
print(", ", terminator: "")
}</lang>
}</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,188: Line 2,560:


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>for {set i 1} {$i <= 10} {incr i} {
<syntaxhighlight lang="tcl">for {set i 1} {$i <= 10} {incr i} {
puts -nonewline $i
puts -nonewline $i
if {$i % 5 == 0} {
if {$i % 5 == 0} {
Line 2,195: Line 2,567:
}
}
puts -nonewline ", "
puts -nonewline ", "
}</lang>
}</syntaxhighlight>


=={{header|Transact-SQL}}==
=={{header|Transact-SQL}}==


<syntaxhighlight lang="transact-sql">
<lang Transact-SQL>
DECLARE @i INT = 0;
DECLARE @i INT = 0;
DECLARE @str VarChar(40) = '';
DECLARE @str VarChar(40) = '';
Line 2,214: Line 2,586:
SET @str = @str +', ';
SET @str = @str +', ';
END;
END;
</syntaxhighlight>
</lang>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
$$ MODE TUSCRIPT
numbers=""
numbers=""
Line 2,227: Line 2,599:
numbers=""
numbers=""
ENDLOOP
ENDLOOP
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,235: Line 2,607:


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
<lang bash>Z=1
<syntaxhighlight lang="bash">Z=1
while (( Z<=10 )); do
while (( Z<=10 )); do
echo -e "$Z\c"
echo -e "$Z\c"
Line 2,244: Line 2,616:
fi
fi
(( Z++ ))
(( Z++ ))
done</lang>
done</syntaxhighlight>


{{works with|Bash}}
{{works with|Bash}}
<lang bash>for ((i=1;i<=10;i++)); do
<syntaxhighlight lang="bash">for ((i=1;i<=10;i++)); do
echo -n $i
echo -n $i
if [ $((i%5)) -eq 0 ]; then
if [ $((i%5)) -eq 0 ]; then
Line 2,254: Line 2,626:
fi
fi
echo -n ", "
echo -n ", "
done</lang>
done</syntaxhighlight>


=={{header|UnixPipes}}==
=={{header|UnixPipes}}==
<lang bash>yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,</lang>
<syntaxhighlight lang="bash">yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
{{trans|Python}}
{{trans|Python}}
<lang ursa>decl int i
<syntaxhighlight lang="ursa">decl int i
for (set i 1) (< i 11) (inc i)
for (set i 1) (< i 11) (inc i)
if (= (mod i 5) 0)
if (= (mod i 5) 0)
Line 2,268: Line 2,640:
end if
end if
out i ", " console
out i ", " console
end for</lang>
end for</syntaxhighlight>


=={{header|Vala}}==
=={{header|Vala}}==
<lang vala>for (int i = 1; i <= 10; i++) {
<syntaxhighlight lang="vala">for (int i = 1; i <= 10; i++) {
stdout.printf("%d", i);
stdout.printf("%d", i);
if (i % 5 == 0) {
if (i % 5 == 0) {
Line 2,278: Line 2,650:
}
}
stdout.printf(", ");
stdout.printf(", ");
}</lang>
}</syntaxhighlight>


=={{header|VBA}}==
=={{header|VBA}}==
<lang VB>Public Sub LoopContinue()
<syntaxhighlight lang="vb">Public Sub LoopContinue()
Dim value As Integer
Dim value As Integer
For value = 1 To 10
For value = 1 To 10
Line 2,292: Line 2,664:
End If
End If
Next value
Next value
End Sub</lang>
End Sub</syntaxhighlight>


=={{header|Vedit macro language}}==
=={{header|Vedit macro language}}==
<lang vedit>for (#1 = 1; #1 <= 10; #1++) {
<syntaxhighlight lang="vedit">for (#1 = 1; #1 <= 10; #1++) {
Num_Type(#1, LEFT+NOCR)
Num_Type(#1, LEFT+NOCR)
if (#1 % 5 == 0) {
if (#1 % 5 == 0) {
Line 2,302: Line 2,674:
}
}
Message(", ")
Message(", ")
}</lang>
}</syntaxhighlight>

=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
for i in 1..11 {
print(i)
if i%5==0{
println('')
continue
}
print(', ')
}
}</syntaxhighlight>
{{Out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>


=={{header|Wren}}==
=={{header|Wren}}==
From v0.4.0 Wren has a ''continue'' keyword which works in the expected fashion.
From v0.4.0 Wren has a ''continue'' keyword which works in the expected fashion.
<lang ecmascript>for (i in 1..10) {
<syntaxhighlight lang="wren">for (i in 1..10) {
System.write(i)
System.write(i)
if (i%5 == 0) {
if (i%5 == 0) {
Line 2,315: Line 2,704:
}
}


System.print()</lang>
System.print()</syntaxhighlight>


{{out}}
{{out}}
Line 2,330: Line 2,719:
The way you implement continue in X86 Assembly is the same way as how you would create a loop:
The way you implement continue in X86 Assembly is the same way as how you would create a loop:
you just implement a (conditional) jump to another line of code.
you just implement a (conditional) jump to another line of code.
<lang asm>
<syntaxhighlight lang="asm">
extern _printf
extern _printf


Line 2,418: Line 2,807:
pop ebx
pop ebx
ret
ret
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,427: Line 2,816:
=={{header|XBasic}}==
=={{header|XBasic}}==
{{works with|Windows XBasic}}
{{works with|Windows XBasic}}
<lang xbasic>
<syntaxhighlight lang="xbasic">
PROGRAM "loopcontinue"
PROGRAM "loopcontinue"


Line 2,443: Line 2,832:
END FUNCTION
END FUNCTION
END PROGRAM
END PROGRAM
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,455: Line 2,844:
Only the first three characters of a command are required.
Only the first three characters of a command are required.


<lang XPL0>code CrLf=9, IntOut=11, Text=12;
<syntaxhighlight lang="xpl0">code CrLf=9, IntOut=11, Text=12;
integer N;
integer N;
for N:= 1 to 10 do
for N:= 1 to 10 do
[IntOut(0, N); if remainder(N/5) \#0\ then Text(0, ", ") else CrLf(0)]</lang>
[IntOut(0, N); if remainder(N/5) \#0\ then Text(0, ", ") else CrLf(0)]</syntaxhighlight>


{{Out}}
{{Out}}
Line 2,465: Line 2,854:
6, 7, 8, 9, 10
6, 7, 8, 9, 10
</pre>
</pre>


=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">for i = 1 to 10
print str$(i);
if mod(i, 5) = 0 then
print
continue
end if
print ", ";
next
print
end</syntaxhighlight>



=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>foreach n in ([1..10]){print(n); if(n%5==0){println(); continue;} print(", ")}
<syntaxhighlight lang="zkl">foreach n in ([1..10]){print(n); if(n%5==0){println(); continue;} print(", ")}
// or foreach n in ([1..10]){print(n,(n%5) and ", " or "\n")}</lang>
// or foreach n in ([1..10]){print(n,(n%5) and ", " or "\n")}</syntaxhighlight>

=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");

pub fn main() !void {
const stdout_wr = std.io.getStdOut().writer();
var i: i8 = 1;
while (i <= 10) : (i += 1) {
try stdout_wr.print("{d}", .{i});
if (i == 5) {
try stdout_wr.writeAll("\n");
continue;
}
try stdout_wr.writeAll(", ");
}
}</syntaxhighlight>

Latest revision as of 09:28, 24 March 2024

Task
Loops/Continue
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Show the following output using one loop.

1, 2, 3, 4, 5
6, 7, 8, 9, 10


Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it.


Related tasks



11l

Translation of: Python
L(i) 1..10
   I i % 5 == 0
      print(i)
      L.continue
   print(i, end' ‘, ’)
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

360 Assembly

*        Loops/Continue            12/08/2015
LOOPCONT CSECT
         USING  LOOPCONT,R12
         LR     R12,R15
BEGIN    LA     R8,0
         SR     R5,R5
         LA     R6,1
         LA     R7,10
LOOPI    BXH    R5,R6,ELOOPI       for i=1 to 10
         LA     R3,MVC(R8)
         XDECO  R5,XDEC
         MVC    0(4,R3),XDEC+8
         LA     R8,4(R8)
         LR     R10,R5
         LA     R1,5
         SRDA   R10,32
         DR     R10,R1
         LTR    R10,R10
         BNZ    COMMA
         XPRNT  MVC,80
         LA     R8,0
         B      NEXTI
COMMA    LA     R3,MVC(R8)
         MVC    0(2,R3),=C', '
         LA     R8,2(R8)
NEXTI    B      LOOPI              next i
ELOOPI   XR     R15,R15
         BR     R14
MVC      DC     CL80' '
XDEC     DS     CL16
         YREGS  
         END    LOOPCONT
Output:
   1,    2,    3,    4,    5
   6,    7,    8,    9,   10

Ada

Ada doesn't have a continue statement, so we have to use a goto statement. The previous submitter said continue is not needed. In this example it is indeed not needed, but that is not always the case. An example is a loop where a number of interdependent conditions are checked before executing the main body of the loop. Without a continue statement (or goto), one ends up with nested statements with the main body to the far right of the page.

B.N. You should always try to avoid using a goto, but if you really must, it's there in Ada.

P.S. it is often simplest to place the label on top of the loop, as in real life the need occurs when reading input, so there is no range condition in the loop and we can forgo the null statement.

with Ada.Text_IO;
use Ada.Text_IO;

procedure Loop_Continue is
begin
        for I in 1..10 loop
                Put (Integer'Image(I));
                if I = 5 or I = 10 then
                        New_Line;
                        goto Continue;
                end if;
                Put (",");
                <<Continue>>  --Ada 2012 no longer requires a statement after the label
        end loop;
end Loop_Continue;

N. This is a more true-to-Ada strategy for 'continue' comprising of an outer iteration loop and an inner labeled single-pass loop. This is a safer strategy than using goto which could be problematic when dealing with complex nested loops.

with Ada.Text_IO;
use Ada.Text_IO;

procedure Loop_Continue is
begin
        Print_All:
        for I in 1 .. 10 loop
                Print_Element: loop
                        Put (Integer'Image(I));
                        if I = 5 or I = 10 then
                                New_Line;
                                exit Print_Element;
                        end if;
                        Put (",");
                exit Print_Element;
                end loop Print_Element;
        end loop Print_All;
end Loop_Continue;

Agena

Agena doesn't have a continue statement, conditional statements can be used instead.

for i to 10 do
    write( i );
    if i % 5 = 0
    then write( "\n" )
    else write( ", " )
    fi
od

Aikido

foreach i 1..10 {
    print (i)
    if ((i % 5) == 0) {
        println()
        continue
    } 
    print (", ")
}

ALGOL 60

 begin
   integer i;
   for i:=1 step 1 until 10 do begin
     outinteger(i);
     if i=(i div 5)*5 then
       outimage
     else
       outstring(", ")
     end
 end
Output:
         +1  ,          +2  ,          +3  ,          +4  ,          +5
         +6  ,          +7  ,          +8  ,          +9  ,         +10

ALGOL 68

Works with: ALGOL 68 version Revision 1 - no extensions to language used
Works with: ALGOL 68G version Any - tested with release 1.18.0-9h.tiny
Works with: ELLA ALGOL 68 version Any (with appropriate job cards) - tested with release 1.8-8d

ALGOL 68 has no continue reserved word, nor does it need one. The continue reserved word is only syntactic sugar for operations that can be achieved without it as in the following example:

FOR i FROM 1 TO 10 DO
  print ((i, 
    IF i MOD 5 = 0 THEN
      new line
    ELSE
      ","
    FI
  ))
OD
Output:
         +1,         +2,         +3,         +4,         +5
         +6,         +7,         +8,         +9,        +10

ALGOL W

Algol W doesn't have a continue statement - conditional statements can be used instead.

begin
    i_w := 1; s_w := 0; % set output format %
    for i := 1 until 10 do begin
        writeon( i );
        if i rem 5 = 0
        then write()
        else writeon( ", " )
    end for_i
end.

AppleScript

set table to {return}
repeat with i from 1 to 10
	if i < 5 or (i  6 and i < 10) then
		set end of table to i & ", "
	else if i = 5 or i = 10 then
		set end of table to i & return
	end if
end repeat
return table as string
Output:
"
1, 2, 3, 4, 5
6, 7, 8, 9, 10
"

Arturo

loop 1..10 'i [
    prints i
    if 0 = i%5 [
        print ""
        continue
    ]
    prints ", "
]
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Asymptote

Asymptote's control structures are similar to those in C/C++

for(int i = 1; i <= 10; ++i) {
  write(i, suffix=none);
  if(i % 5 == 0) {
    write("");
    continue;
  } else {
    write(", ", suffix=none);
  }
}

AutoHotkey

Loop, 10 {
  Delimiter := (A_Index = 5) || (A_Index = 10) ? "`n":", "
  Index .= A_Index . Delimiter
}
MsgBox %Index%

AWK

BEGIN {
  for(i=1; i <= 10; i++) {
    printf("%d", i)
    if ( i % 5 == 0 ) {
      print
      continue
    }
    printf(", ")
  }
}

BASIC

Applesoft BASIC

 10  FOR I = 1 TO 10
 20  PRINT I;
 30  IF I -  INT (I / 5) * 5 = 0 THEN  PRINT : GOTO 50"CONTINUE
 40  PRINT ", ";
 50  NEXT

BASIC256

for i = 1 to 10
	print string(i);
	if i mod 5 = 0 then
		print
		continue for
	end if
	print ", ";
next
print
end

BBC BASIC

BBC BASIC doesn't have a 'continue' statement so the remainder of the loop must be made conditional.

      FOR i% = 1 TO 10
        PRINT ; i% ;
        IF i% MOD 5 = 0 PRINT ELSE PRINT ", ";
      NEXT

Commodore BASIC

Commodore BASIC also doesn't have a 'continue' statement. In this example, a GOTO statement is used to simulate 'CONTINUE'. However, Commodore BASIC doesn't have a modulo (remainder) operator, so value of I/5 is check against INT(I/5). If they are the same, the remainder is zero.

10 FOR I = 1 to 10
20 PRINT I;
30 IF INT(I/5) = I/5 THEN PRINT : GOTO 50
40 PRINT ", ";
50 NEXT

FreeBASIC

' FB 1.05.0 Win64
For i As Integer = 1 To 10
  Print Str(i);
  If i Mod 5 = 0 Then
    Print
    Continue For
  End If
  Print ", ";
Next

Print
Sleep
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

IS-BASIC

100 FOR I=1 TO 10
110   PRINT STR$(I);
120   IF MOD(I,5)=0 THEN
130     PRINT 
140   ELSE
150     PRINT ", ";
160   END IF
170 NEXT

Liberty BASIC

for i =1 to 10
    if i mod 5 <>0 then print i; ", "; else print i
next i
end

PureBasic

OpenConsole()

For i.i = 1 To 10
  Print(Str(i))
  If i % 5 = 0
    PrintN("")
    Continue
  EndIf
  Print(",")
Next

Repeat: Until Inkey() <> ""

QB64

Dim i As Integer
For i = 1 To 10
    Print LTrim$(Str$(i));
    If i Mod 5 = 0 Then
        Print
        _Continue
    End If
    Print ", ";
Next

Run BASIC

Works with: QBasic
for i = 1 to 10
    if i mod 5 <> 0 then print i;", "; else print i
next i

Sinclair ZX81 BASIC

This probably isn't the most idiomatic way to produce the specified output—but it does illustrate ZX81 BASIC's equivalent of if <condition> continue, which is IF <condition> THEN NEXT <loop-control variable>.

10 FOR I=1 TO 10
20 PRINT I;
30 IF I/5=INT (I/5) THEN PRINT
40 IF I/5=INT (I/5) THEN NEXT I
50 PRINT ", ";
60 NEXT I

TI-89 BASIC

count()
Prgm 
  ""→s
  For i,1,10
    s&string(i)→s
    If mod(i,5)=0 Then
      Disp s
      ""→s
      Cycle
    EndIf
    s&", "→s
  EndFor
EndPrgm

Ti-89 lacks support for multi-argument display command or controlling the print position so that one can print several data on the same line. The display command (Disp) only accepts one argument and prints it on a single line (causing a line a feed at the end, so that the next Disp command will print in the next line). The solution is appending data to a string (s), using the concatenator operator (&), by converting numbers to strings, and then printing the string at the end of the line.

True BASIC

FOR i = 1 TO 10
    PRINT STR$(i);
    IF REMAINDER(i, 5) = 0 THEN
       PRINT
    ELSE                          !No existe el comando CONTINUE
       PRINT ", ";
    END IF
NEXT i
PRINT
END

VB-DOS, PDS

OPTION EXPLICIT

DIM i AS INTEGER

CLS
FOR i = 1 TO 10
 PRINT STR$(i);
 IF (i MOD 5) THEN PRINT ",";  ELSE PRINT
NEXT i
END

Visual Basic .NET

For i = 1 To 10
    Console.Write(i)
    If i Mod 5 = 0 Then
        Console.WriteLine()
    Else
        Console.Write(", ")
    End If
Next

bc

Requires a bc with the print and continue statements. POSIX bc has not these statements.

Works with: OpenBSD bc
for (i = 1; i <= 10; i++) {
	print i
	if (i % 5) {
		print ", "
		continue
	}
	print "\n"
}
quit

BCPL

In BCPL, the continue statement is named loop.

get "libhdr"

let start() be
    for i = 1 to 10
    $(  writen(i)
        if i rem 5 = 0
        $(  wrch('*N')
            loop
        $)
        writes(", ")
    $)
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Befunge

Befunge outputs numbers with a space after them, so the formatting is slightly off in this version.

1>:56+\`#v_@
 +v %5:.:<
 1>#v_55+,v
 ^        <
    >" ,",,v
 ^         <

This version outputs a 'backspace' ASCII character to try to correct the format, but it may or may not work depending on if the character is accounted for by the output

1>:56+\`#v_@
 +v5:,8.:<
 1>%#v_55+,v
 ^         <
     >" ,",v
 ^        ,<

Bracmat

Bracmat has no continue statement.

( 0:?i
&   whl
  ' ( 1+!i:~>10:?i
    &   put
      $ ( str
        $ ( !i
            (mod$(!i.5):0&\n|", ")
          )
        )
    )
);

C

Translation of: C++
for(int i = 1;i <= 10; i++){
   printf("%d", i);
   if(i % 5 == 0){
      printf("\n");
      continue;
   }
   printf(", ");
}

C#

Translation of: Java
using System;

class Program {
    static void Main(string[] args) {
        for (int i = 1; i <= 10; i++) {
            Console.Write(i);

            if (i % 5 == 0) {
                Console.WriteLine();
                continue;
            }

            Console.Write(", ");
        }
    }
}

C++

Translation of: Java
for(int i = 1;i <= 10; i++){
   cout << i;
   if(i % 5 == 0){
      cout << endl;
      continue;
   }
   cout << ", ";
}

C3

Translation of: Java
for (int i = 1; i <= 10; i++)
{
   io::print(i);
   if (i % 5 == 0)
   {
      io::printn();
      continue;
   }
   io::print(", ");
}

Chapel

for i in 1..10 {
        write(i);
        if i % 5 == 0 then {
                writeln();
                continue;
        }
        write(", ");
}

Clipper

LOOP keyword is used here instead of continue.

Works as is with Harbour 3.0.0 (Rev. 16951)

FOR i := 1 TO 10
   ?? i
   IF i % 5 == 0
      ?
      LOOP
   ENDIF
   ?? ", "
NEXT

Clojure

Clojure doesn't have a continue keyword. It has a recur keyword, although I prefer to work with ranges in this case.

(doseq [n (range 1 11)]
  (print n)
  (if (zero? (rem n 5))
      (println)
      (print ", ")))

To address the task, however, here's an example loop/recur:

(loop [xs (range 1 11)]
  (when-let [x (first xs)]
    (print x)
    (if (zero? (rem x 5))
        (println)
        (print ", "))
    (recur (rest xs))))

COBOL

       IDENTIFICATION DIVISION.
       PROGRAM-ID. loop-continue.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  i PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL 10 < i
               DISPLAY i WITH NO ADVANCING

               IF FUNCTION MOD(i, 5) = 0
                   DISPLAY SPACE
                   EXIT PERFORM CYCLE
               END-IF

               DISPLAY ", " WITH NO ADVANCING
           END-PERFORM

           GOBACK
           .

Note: COBOL does have a CONTINUE verb, but this is a no-operation statement used in IF and EVALUATE statements.

ColdFusion

Remove the leading space from the line break tag.

<cfscript>
  for( i = 1; i <= 10; i++ )
  {
    writeOutput( i );
    if( 0 == i % 5 )
    {
      writeOutput( "< br />" );
      continue;
    }
    writeOutput( "," );
  }
</cfscript>

Common Lisp

Common Lisp doesn't have a continue keyword, but the do iteration construct does use an implicit tagbody, so it's easy to go to any label. Four solutions follow. The first pushes the conditional (whether to print a comma and a space or a newline) into the format string. The second uses the implicit tagbody and go. The third is a do loop with conditionals outside of the output functions.

(do ((i 1 (1+ i)))
    ((> i 10))
  (format t "~a~:[, ~;~%~]" i (zerop (mod i 5))))

(do ((i 1 (1+ i)))
    ((> i 10))
  (write i)
  (when (zerop (mod i 5))
    (terpri)
    (go end))
  (write-string ", ")
  end)

(do ((i 1 (1+ i)))
    ((> i 10))
  (write i)
  (if (zerop (mod i 5))
    (terpri)
    (write-string ", ")))

These use the loop iteration form, which does not contain an implicit tagbody (though one could be explicitly included). The first uses an explicit condition to omit the rest of the loop; the second uses block/return-from to obtain the effect of skipping the rest of the code in the block which makes up the entire loop body.

(loop for i from 1 to 10
      do (write i)
      if (zerop (mod i 5))
        do (terpri)
      else
        do (write-string ", "))

(loop for i from 1 to 10 do
  (block continue
    (write i)
    (when (zerop (mod i 5))
      (terpri)
      (return-from continue))
    (write-string ", ")))

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;
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

D

import std.stdio;

void main() {
    foreach (i; 1 .. 11) {
        write(i);
        if (i % 5 == 0) {
            writeln();
            continue;
        }
        write(", ");
    }
}
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Shorter version

import std.stdio;

void main()
{
  foreach(i; 1..11) i % 5 ? writef("%s, ", i) : writeln(i);
}

dc

The four commands # n J M are special to OpenBSD dc. The # command starts a comment. The n command prints a number without a newline.

Translation of: bc
Works with: OpenBSD dc
1 si		# i = 1
[2Q]sA		# A = code to break loop
[[, ]P 1J]sB	# B = code to print comma, continue loop
[
 li n		# print i
 li 5 % 0 !=B	# call B if i % 5
 [
]P              # print newline
 M		# mark from calling B
 li 1 + si	# i += 1
 li 10!<C	# continue loop if 10 >= i
]sC li 10!<C	# enter loop if 10 >= i

This program uses J and M to force the next iteration of a loop. The nJ command breaks n levels of brackets (like nQ does so), but then skips to the next M command. One can place M at the end of the iteration.

Delphi

program DoLoop(output);
var
  i: integer;
begin
  for i := 1 to 10 do
  begin
    write(i);
    if i mod 5 = 0 then
    begin
      writeln;
      continue;
    end;
    write(', ');
  end;
end.
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

DWScript

var i : Integer;

for i := 1 to 10 do begin
   Print(i);
   if i mod 5 = 0 then begin
      PrintLn('');
      continue;
   end;
   Print(', ');
end;

Dyalect

Translation of: Swift
for i in 1..10 {
    print(i, terminator: "")
    if i % 5 == 0 {
        print()
        continue
    }
    print(", ", terminator: "")
}
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Ela

Direct Approach

open monad io
 
loop n = 
  if n > 10 then do
      return () 
    else do
      putStr (show n)
      putStr f
      loop (n + 1)
  where f | n % 5 == 0 = "\r\n"
          | else = ", "

_ = loop 1 ::: IO

Using list

open monad io
 
loop [] = return ()
loop (x::xs) = do
      putStr (show x)
      putStr f
      loop xs
  where f | x % 5 == 0 = "\r\n"
          | else = ", "
 
_ = loop [1..10] ::: IO

This version is more generic and can work for any given range of values.

Elixir

defmodule Loops do
  def continue do
    Enum.each(1..10, fn i ->
      IO.write i
      IO.write if rem(i,5)==0, do: "\n", else: ", "
    end)
  end
end

Loops.continue
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

EMal

for int i = 1; i <= 10; ++i
  write(i)
  if i % 5 == 0
    writeLine()
    continue
  end
  write(", ")
end
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Erlang

%% Implemented by Arjun Sunel
-module(continue).
-export([main/0, for_loop/1]).
 
main() ->
	for_loop(1).
	
for_loop(N)  when N /= 5 , N <10 ->
	io:format("~p, ",[N] ),
	for_loop(N+1);
	
for_loop(N) when N >=10->
	if N=:=10 ->
		io:format("~p\n",[N] )
	end;
	 
for_loop(N) ->
	if N=:=5 ->
		io:format("~p\n",[N] ),
		for_loop(N+1)
	end.
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10
ok

ERRE

FOR I=1 TO 10 DO
   PRINT(I;CHR$(29);)  ! printing a numeric value leaves a blank after it
                       ! chr$(29) delete it.....
   IF I MOD 5=0 THEN
      PRINT
      CONTINUE FOR
   END IF
   PRINT(",";)
END FOR
PRINT

Euphoria

Works with: Euphoria version 4.0.3, 4.0.0 or later
include std\console.e --only for any_key to make running command window easier on windows

for i = 1 to 10 do
    if remainder(i,5) = 0 then
        printf(1, "%d\n", i)
        else
            printf(1,"%d, ", i)
            continue
    end if
end for
any_key()

Version without newline after 10 below.

include std\console.e --only for any_key to make running command window easier on windows

for i = 1 to 10 do
    if remainder(i,5) = 0 then
        switch i do 
            case 10 then
                printf(1,"%d ",i)
                break --new to euphoria 4.0.0+
            case else
                printf(1,"%d\n", i)
        end switch
                
        else
            printf(1,"%d, ", i)
            continue --new to euphoria 4.0.0+
    end if
end for
any_key()

F#

continue is a reserved word, but it has no function. In any case, it is not needed to complete this task.

Translation of: Ada

for i in 1 .. 10 do
  printf "%d" i
  if i % 5 = 0 then
    printf "\n"
  else
    printf ", "

Using Comma quibbling#The Function

let fN g=quibble (Seq.initInfinite(fun n ->if (n+1)%5=0 || (n+1)=List.length g then "\n" else ", ")) g  
fN [1] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
fN [1..9] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
fN [1..10] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
fN [1..11] |> Seq.iter(fun(n,g)->printf "%d%s" n g)
Output:
1
1, 2, 3, 4, 5
6, 7, 8, 9
1, 2, 3, 4, 5
6, 7, 8, 9, 10
1, 2, 3, 4, 5
6, 7, 8, 9, 10
11
 

Factor

There is no built-in continue in Factor.

1 10 [a,b] [ 
    [ number>string write ]
    [ 5 mod 0 = "\n" ", " ? write ] bi
] each

Fantom

While and for loops support continue to jump back to begin the next iteration of the loop.

class LoopsContinue
{
  public static Void main () 
  {
    for (Int i := 1; i <= 10; ++i)
    {
      Env.cur.out.print (i)
      if (i % 5 == 0) 
      {
        Env.cur.out.printLine ("")
        continue
      }
      Env.cur.out.print (", ")
    }
    Env.cur.out.printLine ("")
  }
}

Forth

Although this code solves the task, there is no portable equivalent to "continue" for either DO-LOOPs or BEGIN loops.

: main
  11 1 do
    i dup 1 r.
    5 mod 0= if cr else [char] , emit space then
  loop ;

Fortran

Works with: Fortran version 90 and later
do i = 1, 10
   write(*, '(I0)', advance='no') i
   if ( mod(i, 5) == 0 ) then
      write(*,*)
      cycle
   end if
   write(*, '(A)', advance='no') ', '
end do
Works with: Fortran version 77 and later
C     WARNING: This program is not valid ANSI FORTRAN 77 code. It uses
C     one nonstandard character on the line labelled 5001. Many F77
C     compilers should be okay with it, but it is *not* standard.
C
C     It is also worth noting that FORTRAN 77 uses the command CONTINUE,
C     but not in the semantic, looping sense of the word. In FORTRAN,
C     CONTINUE means "do absolutely nothing." It is a placeholder. If
C     anything, it means "continue to the next line."
C
C     Python does the same thing with `pass`; C and its family of
C     languages, with `{/* do nothing */}`. Write CONTINUE when you need
C     to write something but have nothing to write.
C
C     This page on Rosetta Code is about a very different "continue"
C     statement that tells a loop to go back to the beginning. In
C     FORTRAN, we use (you guessed it!) a GOTO to accomplish this.
      PROGRAM CONTINUELOOP
        INTEGER I

        DO 10 I = 1, 10
C         Is it five or ten?
          IF (MOD(I, 5) .EQ. 0) THEN
C           If it is, write a newline and no comma.
            WRITE (*,5000) I

C           Continue the loop; that is, skip to the end of the loop.
            GOTO 10
          ENDIF

C         Write I with a comma and no newline.
          WRITE (*,5001) I

C       Again, in this case, CONTINUE is completely unrelated to the
C       semantic, looping sense of the word.
   10   CONTINUE

        STOP

C       This will print an integer and a newline (no comma).
 5000   FORMAT (I3)

C       Standard FORTRAN 77 is completely incapable of completing a
C       WRITE statement without printing a newline. If you want to print
C       five integers in standard code, you have to do something like
C       this:
C
C           FORMAT (I3, ',', I3, ',', I3, ',', I3, ',', I3)
C
C       Writing `1, 2, 3, 4, 5` and then `6, 7, 8, 9, 10` to that format
C       would produce the following two lines:
C
C             1,  2,  3,  4,  5
C             6,  7,  8,  9, 10
C
C       However, this code exists to demonstrate continuing a FORTRAN 77
C       loop and not to demonstrate how to get around its rigidity about
C       newlines.
C
C       The dollar sign at the end of the format is a nonstandard
C       character. It tells the compiler not to print a newline. If you
C       are actually using FORTRAN 77, you should figure out what your
C       particular compiler accepts. If you are actually using Fortran
C       90 or later, you should replace this line with the commented
C       line that follows it.
 5001   FORMAT (I3, ',', $)
C5001   FORMAT (I3, ',', ADVANCE='NO')
      END

Relying instead upon the looping features of FORMAT

For historical reasons, 6 is often the default unit number for standard output.

      WRITE (6,1) (I,I = 1,10)
    1 FORMAT (4(1X,I0,","),1X,I0)
      END

Here the break and continuation comes through the workings of the FORMAT interpreter. The feature 4(etc) means four repetitions of the format items within the brackets, and as each datum from the WRITE statement arrives, it is aligned with the next format item that can receive a datum, the I-format specifier (here I0, which means an integer of only as many digits as are needed for the value) and until such a reciever is encountered, intervening format items are acted upon - 1X means "one space", and the quotes surround a text literal. Accordingly, the first datum generates a space, a one-digit value, and a comma, as does the second and so on. When the sixth datum is received, the end of the format statement has been reached, and the convention is to write the current line and start a new line of output, and further, go back in the FORMAT specification to the first-encountered open-bracket symbol (the rightmost) which in this case is not the beginning of the FORMAT statement but the one that has a repetition count of four in front of it, and, resume interpretation. When the last datum has been accepted, naturally, the line is printed.

An alternative might be FORMAT (4(I2,","),I2) but that would generate

1, 2, 3, 4, 5
6, 7, 8, 9,10

Alternatively, FORMAT (4(I2,","),I2,/,4(I2,","),I3) would do the trick but there would no longer be the loop, break, continue aspect to the interpretation of the FORMAT statement, merely a grinding through a list.

This sort of scheme facilitates a compact way of printing a table with a heading, where the WRITE statement simply pours forth the data and relies on something like FORMAT("heading",/,(complex details for one line)) - thus printing the table line-by-line with only the first line having the heading, a saving on having a write and format statement pair for the heading and a second pair for the table body.

FutureBasic

include "NSLog.incl"

long num

for num = 1 to 10
  if ( num mod 5 )
    NSLog(@"%ld, \b",num)
  else
    NSLog(@"%ld",num)
  end if
next

HandleEvents

Gambas

Click this link to run this code

Public Sub Main()
Dim siCount As Short

For siCount = 1 To 10
  Print siCount;
  If siCount <> 5 And siCount <> 10 Then Print ",";
  If siCount = 5 Then Print gb.NewLine;
Next

End

Output:

1,2,3,4,5
6,7,8,9,10

GAP

for i in [1 .. 11] do
    if RemInt(i, 5) = 0 then
        Print(i, "\n");
        continue;
    fi;
    Print(i, ", ");
od;

# 1, 2, 3, 4, 5
# 6, 7, 8, 9, 10

GDScript

Works with: Godot version 4.0.1
Translation of: 11l
extends MainLoop


func _process(_delta: float) -> bool:
	for i in range(1,11):
		if i % 5 == 0:
			print(i)
			continue
		printraw(i, ", ")

	return true # Exit


GML

for(i = 1; i <= 10; i += 1)
    {
    show_message(string(i))
    i += 1
    if(i <= 10)
        continue
    }

Go

package main

import "fmt"

func main() {
    for i := 1; i <= 10; i++ {
        fmt.Printf("%d", i)
        if i%5 == 0 {
            fmt.Printf("\n")
            continue
        }
        fmt.Printf(", ")
    }
}
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Groovy

for (i in 1..10) {
    print i
    if (i % 5 == 0) {
        println ()
        continue
    }
    print ', '
}

Haskell

As a functional language, it is not idiomatic to have true loops - recursion is used instead. Below is one of many possible implementations of the task. The below code uses a guard (| symbol) to compose functions differently for the two alternative output paths, instead of using continue like in an imperative language.

import Control.Monad (forM)
main = forM [1..10] out
    where
      out x | x `mod` 5 == 0 = print x
            | otherwise = (putStr . (++", ") . show) x

Haxe

for (i in 1...11) {
  Sys.print(i);
  if (i % 5 == 0) {
    Sys.print('\n');
    continue;
  }
  Sys.print(', ');
}

HicEst

DO i = 1, 10
  IF( MOD(i, 5) == 1 ) THEN
      WRITE(Format="i3") i
    ELSE
      WRITE(APPend, Format=" ',', i3 ") i
    ENDIF
ENDDO

Icon and Unicon

The following code demonstrates the use of 'next' (the reserved word for 'continue'):

procedure main()
every writes(x := 1 to 10) do {
   if x % 5 = 0 then {
      write()
      next         
      }
   writes(", ")
   }
end

However, the output sequence can be written without 'next' and far more succinctly as:

every writes(x := 1 to 10, if x % 5 = 0 then "\n" else ", ")

Io

for(i,1,10,
    write(i)
    if(i%5 == 0, writeln() ; continue)
    write(" ,")
)

J

J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way:

_2}."1'lq<, >'8!:2>:i.2 5

J does support loops for those times they can't be avoided (just like many languages support gotos for those time they can't be avoided).

3 : 0 ] 10 
        z=.''
        for_i. 1 + i.y do.
            z =. z , ": i

             if. 0 = 5 | i do.
                  z 1!:2 ]2 
                  z =. ''
                  continue. 
             end. 

             z =. z , ', '
        end.
     i.0 0
   )

Though it's rare to see J code like this.

Jakt

fn main() {
    for i in 1..11 {
        if i % 5 == 0 {
            println("{}", i)
            continue
        }
        print("{}, ", i)
    }
}

Java

for(int i = 1;i <= 10; i++){
   System.out.print(i);
   if(i % 5 == 0){
      System.out.println();
      continue;
   }
   System.out.print(", ");
}

JavaScript

Using the print() function from Rhino or SpiderMonkey.

var output = "";
for (var i = 1; i <= 10; i++) {
  output += i; 
  if (i % 5 == 0) {
    print(output);
    output = "";
    continue;
  } 
  output += ", ";
}


Stepping back from any assumption that repetitive patterns of computation necessarily entail 'loops', and using a functional idiom of JavaScript, we can make the value of one or more subexpressions in a reduce() fold conditional on any special cases that we define.

For example:

function rng(n) {
  return n ? rng(n - 1).concat(n) : [];
}

console.log(
  rng(10).reduce(
    function (a, x) {
      return a + x.toString() + (x % 5 ? ', ' : '\n');
    }, ''
  )
);

Output:

1, 2, 3, 4, 5
6, 7, 8, 9, 10

jq

jq does not have a "continue" statement. In jq 1.4, the simplest way to accomplish the given task is probably as follows:

reduce range(1;11) as $i
  (""; . + "\($i)" + (if $i % 5 == 0 then "\n" else ", " end))

Jsish

/* Loop/continue in jsish */
for (var i = 1; i <= 10; i++) {
    printf("%d", i);
    if (i % 5 == 0) {
        printf("\n");
        continue;
    }
    printf(", ");
}
Output:
prompt$ jsish loop-continue.jsi
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Julia

for i in 1:10
    print(i)
    if i%5 == 0
        println()
        continue
    end
    print(", ")
end
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Kotlin

// version 1.1.2

fun main(args: Array<String>) {
    for(i in 1 .. 10) {
        if (i % 5 == 0) {
            println(i)
            continue
        }
        print("$i, ")
    }
}
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Lambdatalk

{def loops_continue
 {lambda {:i}
  {if {> :i 10}
   then (end of loop)
   else {if {= :i 6} then {br}:i else :i}
        {if {= :i 10} then . else ,}
        {loops_continue {+ :i 1}}}}}
-> loops_continue

{loops_continue 0}
-> 0, 1, 2, 3, 4, 5, 
6, 7, 8, 9, 10. (end of loop)

Lang

$i = 0
while($i < 10) {
	$i += 1
	
	if($i % 5 === 0) {
		fn.println($i)
		
		con.continue
	}
	
	fn.print($i\,\s)
}
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

langur

for .i of 10 {
    write .i
    if .i div 5 { writeln(); next }
    write ", "
}

Lasso

loop(10) => {^
	loop_count
	loop_count % 5 ? ', ' | '\r'
	loop_count < 100 ? loop_continue
	'Hello, World!' // never gets executed
^}

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
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Lingo

str = ""
repeat with i = 1 to 10
  put i after str
  if i mod 5 = 0 then
    put RETURN after str
    next repeat
  end if
  put ", " after str
end repeat
put str

Lisaac

1.to 10 do { i : INTEGER;
  i.print;
  (i % 5 = 0).if { '\n'.print; } else { ','.print; };
};

LiveCode

repeat with n = 1 to 10
    put n 
    if n is 5 then put return
    if n < 10 and n is not 5 then put "," 
end repeat

Lua

for i = 1, 10 do
    io.write( i )
    if i % 5 == 0 then
        io.write( "\n" )
    else
    	io.write( ", " ) 
    end
end

or

for i = 1, 10 do
    io.write( i )
    if i % 5 == 0 then
        io.write( "\n" )
        goto continue
    end
    io.write( ", " ) 
    ::continue::
end

M2000 Interpreter

Module Checkit {
      \\ A For {} loop
      For i=1 to 10 {
            Print i;
            if i mod 5 Else Print : continue
            Print ",";
      }
      Print i=11
      \\ A For Next loop
      For i=1 to 10
            Print i;
            if i mod 5 Else Print : continue
            Print ",";
      Next i
      Print i=11
      \\ A for loop using  a block and a Loop statement
      i=0
      {     i++
            if i>10  then Exit
            loop
            Print i;
            if i mod 5 Else Print : continue
            Print ",";
       }
      Print i=11
      \\ as above but end value for i=10 not 11
      i=0
      {     i++
            if i<10  then loop
            Print i;
            if i mod 5 Else Print : continue
            Print ",";
       }
      Print i=10  ' not 11 but 10
}
Checkit

Maple

for i from 1 to 10 do
        printf( "%d", i );
        if irem( i, 5 ) = 0 then
                printf( "\n" );
                next
        end if;
        printf( ", " )
end do:

This can also be done as follows, but without the use of "next".

for i to 10 do
        printf( "%d%s", i, `if`( irem( i, 5 ) = 0, "\n", ", " ) )
end do:

Mathematica/Wolfram Language

tmp = "";
For[i = 1, i <= 10, i++,
  tmp = tmp <> ToString[i];
  If[Mod[i, 5] == 0,
   tmp = tmp <> "\n";
   ,
   tmp = tmp <> ", ";
   ];
  ];
Print[tmp]

MATLAB / Octave

Loops are considered slow in Matlab and Octave, it is preferable to vectorize the code.

disp([1:5; 6:10])

or

disp(reshape([1:10],5,2)')

A non-vectorized version of the code is shown below in Octave

for i = 1:10
  printf(' %2d',  i);
  if ( mod(i, 5) == 0 ) 
    printf('\n');
    continue
  end
end

Maxima

/* There is no "continue" in Maxima, the easiest is using a "if" instead */
block(
   [s: ""],
   for n thru 10 do (
      s: sconcat(s, n),
      if mod(n, 5) = 0 then (
         ldisp(s),
         s: ""
      ) else (
         s: sconcat(s, ", ")
      )
   )
)$

Using sprint and newline

for n:1 thru 10 do ( 
         sprint(n), 
         if n=5 then newline())$

MAXScript

for i in 1 to 10 do
(
    format "%" i
    if mod i 5 == 0 then
    (
        format "\n"
        continue
    )   continue
    format ", "
)

Insert non-formatted text here

Metafont

Metafont has no a continue (or similar) keyword. As the Ada solution, we can complete the task just with conditional.

string s; s := "";
for i = 1 step 1 until 10:
if i mod 5 = 0:
  s := s & decimal i & char10;
else:
  s := s & decimal i & ", "
fi; endfor
message s;
end

Since message append always a newline at the end, we need to build a string and output it at the end, instead of writing the output step by step.

Note: mod is not a built in; like TeX, "bare Metafont" is rather primitive, and normally a set of basic macros is preloaded to make it more usable; in particular mod is defined as

primarydef x mod y = (x-y*floor(x/y)) enddef;

Modula-3

Modula-3 defines the keyword RETURN as an exception, but when it is used with no arguments it works just like continue in C.

Note, however, that RETURN only works inside a procedure or a function procedure; use EXIT otherwise.

Module code and imports are omitted.

FOR i := 1 TO 10 DO
  IO.PutInt(i);
  IF i MOD 5 = 0 THEN
    IO.Put("\n");
    RETURN;
  END;
  IO.Put(", ");
END;

MOO

s = "";
for i in [1..10]
  s += tostr(i);
  if (i % 5 == 0)
    player:tell(s);
    s = "";
    continue;
  endif
  s += ", ";
endfor

Neko

/**
 Loops/Continue in Neko
 Tectonics:
   nekoc loops-continue.neko
   neko loops-continue
*/

var index = 0;

while index < 10 {
  index += 1;
  $print(index);
  if $not($istrue(index % 5)) {
    $print("\n");

    continue;

  }
  $print(", ");
}
Output:
prompt$ nekoc loops-continue.neko
prompt$ neko loops-continue.n
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Nemerle

Translation of: C#
using System;
using System.Console;
using Nemerle.Imperative;

module Continue
{
    Main() : void
    {
        foreach (i in [1 .. 10])
        {
            Write(i);
            when (i % 5 == 0) {WriteLine(); continue;}
            Write(", ");
        }
    }
}

NetRexx

/* NetRexx */
options replace format comments java crossref savelog symbols nobinary

  say
  say 'Loops/Continue'

  nul = '\-'
  loop i_ = 1 to 10
    say i_.right(2) || nul
    if i_ // 5 = 0 then do
      say
      iterate i_
      end
    say ', ' || nul
        
    end i_

NewLISP

(for (i 1 10)
  (print i)
  (if (= 0 (% i 5))
      (println)
    (print ", ")))

Nim

Translation of: Python
for i in 1..10:
  if i mod 5 == 0:
    echo i
    continue
  stdout.write i, ", "

NS-HUBASIC

10 FOR I=1 TO 10
20 PRINT I;
30 IF I-I/5*5=0 THEN PRINT :GOTO 50"CONTINUE
40 PRINT ",";
50 NEXT

Nu

for i in 1..10 {
	print -n $i
	if $i mod 5 == 0 {
		print ""
		continue
	}
	print -n ", "
}

Objeck

class Continue {
  function : Main(args : String[]) ~ Nil {
    for(i := 1; i <= 10; i += 1;) {
      if(i = 5) {
        "{$i}, "->PrintLine();
        continue;
      };
      "{$i}, "->Print();
    };
  }
}

OCaml

There is no continue statement for for loops in OCaml, but it is possible to achieve the same effect with an exception.

# for i = 1 to 10 do
    try
      print_int i;
      if (i mod 5) = 0 then raise Exit;
      print_string ", "
    with Exit ->
      print_newline()
  done
  ;;
1, 2, 3, 4, 5
6, 7, 8, 9, 10
- : unit = ()

Though even if the continue statement does not exist, it is possible to add it with camlp4.

Octave

v = "";
for i = 1:10
  v = sprintf("%s%d", v, i);
  if ( mod(i, 5) == 0 ) 
    disp(v)
    v = "";
    continue
  endif
  v = sprintf("%s, ", v);
endfor

Oforth

: loopCont 
| i | 
   10 loop: i [ 
      i dup print 5 mod ifZero: [ printcr continue ]
      "," . 
      ] ;

Ol

We use continuation to break the execution of the inner body.

(let loop ((i 1))
   (when (less? i 11)
      (call/cc (lambda (continue)
         (display i)
         (when (zero? (mod i 5))
            (print)
            (continue #f))
         (display ", ")))
      (loop (+ i 1))))
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Oz

By using the "continue" feature of the for-loop, we bind C to a nullary procedure which, when invoked, immediately goes on to the next iteration of the loop.

for I in 1..10 continue:C do
   {System.print I}
   if I mod 5 == 0 then
      {System.printInfo "\n"}
      {C}
   end
   {System.printInfo ", "}
end

PARI/GP

for(n=1,10,
  print1(n);
  if(n%5 == 0, print();continue);
  print1(", ")
)

Pascal

See Delphi

Perl

foreach (1..10) {
    print $_;
    if ($_ % 5 == 0) {
        print "\n";
        next;
    }
    print ', ';
}

It is also possible to use a goto statement to jump over the iterative code section for a particular loop:

foreach (1..10) {
    print $_;
    if ($_ % 5 == 0) {
        print "\n";
        goto MYLABEL;
    }
    print ', ';
MYLABEL:
}

Phix

Library: Phix/basics
with javascript_semantics
for i=1 to 10 do
    printf(1,"%d", i)
    if remainder(i,5)=0 then
        printf(1, "\n")
        continue
    end if
    printf(1,", ")
end for
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

The following works just as well, with identical output

with javascript_semantics
for i=1 to 10 do
    printf(1,"%d", i)
    if remainder(i,5)=0 then
        printf(1, "\n")
    else
        printf(1,", ")
    end if
end for

PHP

for ($i = 1; $i <= 10; $i++) {
    echo $i;
    if ($i % 5 == 0) {
        echo "\n";
        continue;
    }
    echo ', ';
}

Picat

Picat doesn't have a continue statement. So I just use a conditional that ends the body of the predicate.

Translation of: Prolog
Works with: Picat
main =>
    foreach (I in 1..10)
        printf("%d", I),
        if (I mod 5 == 0) then
            nl
        else
            printf(", ")
        end,
    end.
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

PicoLisp

PicoLisp doesn't have an explicit 'continue' functionality. It can always be emulated with a conditional expression.

(for I 10
   (print I)
   (if (=0 (% I 5))
      (prinl)
      (prin ", ") ) )

Pike

int main(){
   for(int i = 1; i <= 10; i++){
      write(sprintf("%d",i));
      if(i % 5 == 0){
         write("\n");
         continue;
      }
      write(", ");
   }
}

PL/I

loop:
do i = 1 to 10;
   put edit (i) (f(3));
   if mod(i,5) = 0 then do; put skip; iterate loop; end;
   put edit (', ') (a);
end;

Plain English

In Plain English, continue is spelled repeat and is the only way to specify an end of a loop.

To run:
Start up.
Demonstrate continue.
Wait for the escape key.
Shut down.

To demonstrate continue:
If a counter is past 10, exit.
Convert the counter to a string.
Write the string on the console without advancing.
If the counter is evenly divisible by 5, write "" on the console; repeat.
Write ", " on the console without advancing.
Repeat.

Pop11

lvars i;
for i from 1 to 10 do
   printf(i, '%p');
   if i rem 5 = 0 then
       printf('\n');
       nextloop;
   endif;
   printf(', ')
endfor;

PowerShell

Translation of: C
for ($i = 1; $i -le 10; $i++) {
    Write-Host -NoNewline $i
    if ($i % 5 -eq 0) {
        Write-Host
        continue
    }
    Write-Host -NoNewline ", "
}

Prolog

Prolog doesn't have a continue statement. So I just use a conditional that ends the body of the predicate.

Works with: GNU Prolog
Works with: SWI Prolog
:- initialization(main).

print_list(Min, Max) :-
    Min < Max,
    write(Min),
    Min1 is Min + 1,
    (
        Min mod 5 =:= 0
        -> nl
        ; write(',')
    ),
    print_list(Min1, Max).

print_list(Max, Max) :-
    write(Max),
    nl.

main :-
    print_list(1, 10).
Output:
1,2,3,4,5
6,7,8,9,10

Python

for i in range(1, 11):
    if i % 5 == 0:
        print(i)
        continue
    print(i, end=', ')

Quackery

10 times
  [ i^ 1+ dup echo
    5 mod 0 = iff
      cr done
    say ", " ]

R

Translation of: C++
for(i in 1:10)
{
   cat(i)
   if(i %% 5 == 0) 
   {
      cat("\n")
      next
   }
   cat(", ")
}

Racket

It is possible to skip loop iterations in Racket, but an explicit continue construct is rarely used:

#lang racket

;; Idiomatic way
(for ([i (in-range 1 11)])
  (if (= (remainder i 5) 0)
      (printf "~a~n" i)
      (printf "~a, " i)))

;; Forces a skip, but not idiomatic because
;; the logic is less obvious
(for ([i (in-range 1 11)]
      #:unless (and (= (remainder i 5) 0)
                    (printf "~a~n" i)))
  (printf "~a, " i))

Raku

(formerly Perl 6)

Translation of: Perl
Works with: Rakudo Star version 2010.08
for 1 .. 10 {
    .print;
    if $_ %% 5 {
        print "\n";
        next;
    }
    print ', ';
}

or without using a loop:

$_.join(", ").say for [1..5], [6..10];

REBOL

REBOL [
	Title: "Loop/Continue"
	URL: http://rosettacode.org/wiki/Loop/Continue
]

; REBOL does not provide a 'continue' word for loop constructs,
; however, you may not even miss it:

print "One liner (compare to ALGOL 68 solution):"
repeat i 10 [prin rejoin [i  either 0 = mod i 5 [crlf][", "]]]

print [crlf "Port of ADA solution:"]
for i 1 10 1 [
	prin i
	either 0 = mod i 5 [
		prin newline
	][
		prin ", "
	]
]
Output:
One liner (compare to ALGOL 68 solution):
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Port of ADA solution:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Red

repeat i 10 [
    prin i
    if i = 10 [break]
    either i = 5 [print ""][prin ","]
]
1,2,3,4,5
6,7,8,9,10

REXX

version 1

(This program could be simpler by using a   then/else   construct, but an   iterate   was used to conform to the task.)

/*REXX program  illustrates  an example of a   DO   loop with an  ITERATE  (continue).  */

  do j=1  for 10                                 /*this is equivalent to:  DO J=1 TO 10 */
  call charout ,  j                              /*write the integer to the terminal.   */
  if j//5\==0  then do                           /*Not a multiple of five?   Then ···   */
                    call charout , ", "          /*  write a comma to the terminal, ··· */
                    iterate                      /* ··· & then go back for next integer.*/
                    end
  say                                            /*force REXX to display on next line.  */
  end   /*j*/
                                                 /*stick a fork in it,  we're all done. */

Program note:   the comma (,) immediately after the   charout   BIF indicates to use the terminal output stream.

output

1, 2, 3, 4, 5
6, 7, 8, 9, 10

version 2

/*REXX program  illustrates  an example of a   DO   loop with an  ITERATE  (continue).  */
$=                                               /*nullify the variable used for display*/
    do j=1  for 10                               /*this is equivalent to:  DO J=1 TO 10 */
    $=$ || j', '                                 /*append the integer to a placeholder. */
    if j//5==0  then say left($, length($) - 2)  /*Is  J  a multiple of five?  Then SAY.*/
    if j==5     then $=                          /*start the display line over again.   */
    end   /*j*/
                                                 /*stick a fork in it,  we're all done. */

output   is the same as the 1st REXX version.

Ring

for i = 1 TO 10
   see i 
   if i % 5 = 0
      see nl
      loop
   ok
   see ", "
next

RPL

You need an IF..THEN..ELSE structure to do that in RPL.

« ""
  1 10 FOR j
     j +
     IF j 5 MOD THEN ", " + ELSE "" END
  NEXT DROP
» 'TASK' STO

Ruby

for i in 1..10 do
   print i
   if i % 5 == 0 then
      puts
      next
   end
   print ', '
end

The "for" look could be written like this:

(1..10).each do |i| ...
1.upto(10) do |i| ...
10.times do |n| i=n+1; ...

Without meeting the criteria (showing loop continuation), this task could be written as:

(1..10).each_slice(5){|ar| puts ar.join(", ")}

Rust

fn main() {
    for i in 1..=10 {
        print!("{}", i);
        if i % 5 == 0 {
            println!();
            continue;
        }
        print!(", ");
    }
}

Salmon

iterate (x; [1...10])
  {
    print(x);
    if (x % 5 == 0)
      {
        print("\n");
        continue;
      };
    print(", ");
  };

Sather

There's no continue! in Sather. The code solve the task without forcing a new iteration.

class MAIN is
  main is
    i:INT;
    loop i := 1.upto!(10);
      #OUT + i;
      if i%5 = 0 then 
        #OUT + "\n";
      else
        #OUT + ", ";
      end;
    end;
  end;
end;

Scala

Scala doesn't have a continue keyword. However, you may not even miss it, if could be used here.

The intuitive way

for (i <- 1 to 10) {
  print(i)
  if (i % 5 == 0) println() else print(", ")
  }

Functional solution

Thinking In Scala© says: we avoid for loops and handle it the Functional way:

  1. Create a Range 1..10 included
  2. Split the range after converting to a List to a pair of List's
  3. A List of the elements of pair of will be created: List(List(1,2,3,4,5),List(6,7,8,9,10))
  4. The map makes for both elements in the List a conversion to a comma separated String, yielding a List of two Strings.
  5. Both comma separated strings will be separated by an EOL
  val a = (1 to 10 /*1.*/ ).toList.splitAt(5) //2.
  println(List(a._1, a._2) /*3.*/ .map(_.mkString(", ") /*4.*/ ).mkString("\n") /*5.*/ )

Scheme

For R7RS Scheme. In this functional solution, there is no "continue". Instead, the "loop" function is directly called in the tail end (this is Tail Recursion).

(import (scheme base)
        (scheme write))

(define (loop-fn start end)
  (define (loop i)
    (if (> i end) #f
        (begin
         (display i)
         (cond ((zero? (modulo i 5))
                (newline) (loop (+ 1 i)))
               (else
                (display ", ")
                (loop (+ 1 i)))))))
  (loop start))

(loop-fn 1 10)

Scilab

Works with: Scilab version 5.5.1
for i=1:10
    printf("%2d ",i)
    if modulo(i,5)~=0 then
      printf(", ")
      continue
    end
    printf("\n")
end
Output:
 1 ,  2 ,  3 ,  4 ,  5 
 6 ,  7 ,  8 ,  9 , 10 

Sidef

for i in (1..10) {
    print i
    if (i %% 5) {
        print "\n"
        next
    }
    print ', '
}

Simula

Works with: SIMULA-67
! Loops/Continue - simula67 - 07/03/2017;
begin
    integer i;
    for i:=1 step 1 until 10 do begin
        outint(i,5);
        if mod(i,5)=0 then begin
            outimage;
            goto loop
        end;
        outtext(", ");
    loop:
    end
 end
Output:
    1,     2,     3,     4,     5
    6,     7,     8,     9,    10

Smalltalk

Works with: Pharo
Works with: Smalltalk/X

actually works with all dialects ¹

1 to: 10 do: [ :i |
    [ :continue |
        i % 5 = 0 ifTrue: [ 
            Transcript show: i; cr.
            continue value ].
        Transcript 
            show: i;
            show: ', '.		
    ] valueWithExit.
]

¹ if valueWithExit is not present in the Block class, it can be added as:

valueWithExit
    ^ self value:[^ nil]

SNOBOL4

SNOBOL4 has no looping statements or conditional statements. Indeed the only branching facilities it has are:

  • Unconditional branch to label. :(LABEL)
  • Branch to label on success. :S(LABEL)
  • Branch to label on failure. :F(LABEL)

(The success/failure labels can both be in the branching clause.)

Despite this, any looping structure can be performed by careful use of these.

          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
Output:
$ snobol4 junk.sno
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Spin

Works with: BST/BSTC
Works with: FastSpin/FlexSpin
Works with: HomeSpun
Works with: OpenSpin
con
  _clkmode = xtal1 + pll16x
  _clkfreq = 80_000_000

obj
  ser : "FullDuplexSerial.spin"

pub main | i
  ser.start(31, 30, 0, 115200)

  repeat i from 1 to 10
    ser.dec(i)
    if i // 5
      ser.str(string(", "))
      next
    ser.str(string(13,10))

  waitcnt(_clkfreq + cnt)
  ser.stop
  cogstop(0)
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

SPL

> n, 1..10
  s += n
  ? n%5, s += ", "
  >> n%5
  #.output(s)
  s = ""
<
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

SQL PL

Works with: Db2 LUW

version 9.7 or higher.

With SQL PL:

--#SET TERMINATOR @

SET SERVEROUTPUT ON @

BEGIN
 DECLARE I SMALLINT DEFAULT 1;

 Loop: WHILE (I <= 10) DO
  CALL DBMS_OUTPUT.PUT(I);
  SET I = I + 1;
  IF (MOD(I - 1, 5) = 0) THEN
   CALL DBMS_OUTPUT.PUT_LINE(' ');
   ITERATE Loop;
  END IF;
  CALL DBMS_OUTPUT.PUT(', ');
 END WHILE Loop;
END @

Output:

db2 => BEGIN
...
db2 (cont.) => END @
DB20000I  The SQL command completed successfully.

1, 2, 3, 4, 5
6, 7, 8, 9, 10

Stata

See continue in Stata help. Notice that the _continue option of display has another purpose: it suppresses the automatic newline at the end of the display command.

forvalues n=1/10 {
	display `n' _continue
	if mod(`n',5)==0 {
		display
		continue
	}
	display ", " _continue
}

Suneido

ob = Object()
for (i = 1; i <= 10; ++i)
    {
    ob.Add(i)
    if i is 5
        {
        Print(ob.Join(','))
        ob = Object()
        }
    }
Print(ob.Join(','))
Output:
1,2,3,4,5
6,7,8,9,10
ok

Swift

for i in 1...10 {
    print(i, terminator: "")
    if i % 5 == 0 {
        print()
        continue
    }
    print(", ", terminator: "")
}
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Tcl

for {set i 1} {$i <= 10} {incr i} {
   puts -nonewline $i
   if {$i % 5 == 0} {
      puts ""
      continue
   }
   puts -nonewline ", "
}

Transact-SQL

DECLARE @i INT = 0;
DECLARE @str VarChar(40) = '';
WHILE @i<10
  BEGIN
    SET @i = @i + 1;
    SET @str = @str + CONVERT(varchar(2),@i);
    IF @i % 5 = 0
      BEGIN
        PRINT @str;
        SET @str =''
        CONTINUE;
      END
    SET @str = @str +', ';
  END;

TUSCRIPT

$$ MODE TUSCRIPT
numbers=""
LOOP n=1,10
numbers=APPEND (numbers,", ",n)
rest=n%5
IF (rest!=0) CYCLE
 PRINT numbers
 numbers=""
ENDLOOP
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

UNIX Shell

Z=1
while (( Z<=10 )); do
    echo -e "$Z\c"
    if (( Z % 5 != 0 )); then
        echo -e ", \c"
    else
        echo -e ""
    fi
    (( Z++ ))
done
Works with: Bash
for ((i=1;i<=10;i++)); do
  echo -n $i
  if [ $((i%5)) -eq 0 ]; then
    echo
    continue
  fi
  echo -n ", "
done

UnixPipes

yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,

Ursa

Translation of: Python
decl int i
for (set i 1) (< i 11) (inc i)
        if (= (mod i 5) 0)
                out i endl console
                continue
        end if
        out i ", " console
end for

Vala

for (int i = 1; i <= 10; i++) {
  stdout.printf("%d", i);
  if (i % 5 == 0) {
    stdout.printf("\n");
    continue;
  }
  stdout.printf(", ");
}

VBA

Public Sub LoopContinue()
    Dim value As Integer
    For value = 1 To 10
        Debug.Print value;
        If value Mod 5 = 0 Then
            'VBA does not have a continue statement
            Debug.Print
        Else
            Debug.Print ",";
        End If
    Next value
End Sub

Vedit macro language

for (#1 = 1; #1 <= 10; #1++) {
    Num_Type(#1, LEFT+NOCR)
    if (#1 % 5 == 0) {
        Type_Newline
        Continue
    }
    Message(", ")
}

V (Vlang)

fn main() {
    for i in 1..11 {
        print(i)
        if i%5==0{
            println('')
            continue
        }
        print(', ')
    }
}
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

Wren

From v0.4.0 Wren has a continue keyword which works in the expected fashion.

for (i in 1..10) {
    System.write(i)
    if (i%5 == 0) {
        System.print()        
        continue
    }
    System.write(", ")
}

System.print()
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

X86 Assembly

Works with: nasm
Works with: windows

The code got really long, because i manually convert the numbers to ASCII, which gets harder with multiple digits(the number 10). The way you implement continue in X86 Assembly is the same way as how you would create a loop: you just implement a (conditional) jump to another line of code.

extern _printf

section .data
    output db 0,0,0,0
    reversedOutput db 0,0
    
section .text
global _main
_main:
    mov ecx, 0
    looping:
        inc ecx
        mov eax, ecx
        push ecx
        cmp ecx, 5
        je do5
        cmp ecx, 10
        je do10
    don:
        call createOutput
        mov [eax+1], byte 0x2c
        mov [eax+2], byte 0x20
        push eax
        call _printf
        add esp, 4
        pop ecx
        jmp looping
    do5:
        call createOutput
        mov [eax+1], byte 0x0a
        push eax
        call _printf
        add esp, 4
        pop ecx
        jmp looping
    do10:
        call createOutput
        mov [eax+2], byte 0x0a
        push eax
        call _printf
        add esp, 4
        pop ecx
        xor eax, eax
        ret        
    

createOutput: ;parameter in eax
    ;eax between 1 and 99
    push ebx
    mov ecx, 0
    clearOutput:
        mov [output+ecx], byte 0
        cmp ecx, 3
        je next
        inc ecx
        jmp clearOutput
    next:
        mov ecx, 0
        mov ebx, 10
    cOlooping:
        xor edx, edx
        div ebx
        mov [reversedOutput+ecx], dl
        add [reversedOutput+ecx], byte 0x30
        cmp eax, 0
        je reverse
        cmp ecx, 1
        je reverse
        inc ecx
        jmp cOlooping
    reverse:
        mov ecx, -1
        mov ebx, 0
        name:
            inc ecx
            neg ecx
            mov dl, [reversedOutput+ecx+1]
            neg ecx
            cmp dl, 0
            je name
            mov [output + ebx], dl
            inc ebx
            cmp ecx, 1
            jl name
        mov eax, output
        pop ebx
        ret
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

XBasic

Works with: Windows XBasic
PROGRAM "loopcontinue"

DECLARE FUNCTION Entry()

FUNCTION Entry()
  FOR i% = 1 TO 10
    PRINT i%;
    IF i% MOD 5 = 0 THEN
      PRINT
      DO NEXT ' It looks like DO FOR backs to the FOR with the current value of i%
    END IF
    PRINT ", ";
  NEXT i%
END FUNCTION
END PROGRAM
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10

XPL0

Like Ada and ALGOL there's no 'continue' command. The task is solved very simply anyway. The commands 'int' and 'rem' are shown spelled out here. Only the first three characters of a command are required.

code CrLf=9, IntOut=11, Text=12;
integer N;
for N:= 1 to 10 do
        [IntOut(0, N); if remainder(N/5) \#0\ then Text(0, ", ") else CrLf(0)]
Output:
1, 2, 3, 4, 5
6, 7, 8, 9, 10


Yabasic

for i = 1 to 10
  print str$(i);
  if mod(i, 5) = 0 then
    print 
    continue
  end if
  print ", ";
next
print
end


zkl

foreach n in ([1..10]){print(n); if(n%5==0){println(); continue;} print(", ")}
// or foreach n in ([1..10]){print(n,(n%5) and ", " or "\n")}

Zig

const std = @import("std");

pub fn main() !void {
    const stdout_wr = std.io.getStdOut().writer();
    var i: i8 = 1;
    while (i <= 10) : (i += 1) {
        try stdout_wr.print("{d}", .{i});
        if (i == 5) {
            try stdout_wr.writeAll("\n");
            continue;
        }
        try stdout_wr.writeAll(", ");
    }
}