Loops/Continue: Difference between revisions

added RPL
(→‎{{header|Lasso}}: adding Lasso while loop_continue example)
(added RPL)
 
(192 intermediate revisions by 93 users not shown)
Line 1:
{{task|Iteration}}Show the following output using one loop.
[[Category:Loop modifiers]]
{{omit from|EasyLang|No continue statement}}
{{omit from|GUISS}}
{{omit from|M4}}
 
;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.
Try to achieve the result by forcing the next iteration within the loop
upon a specific condition, if your language allows it.
 
 
;Related tasks:
*   [[Loop over multiple arrays simultaneously]]
*   [[Loops/Break]]
*   [[Loops/Continue]]
*   [[Loops/Do-while]]
*   [[Loops/Downward for]]
*   [[Loops/For]]
*   [[Loops/For with a specified step]]
*   [[Loops/Foreach]]
*   [[Loops/Increment loop index within loop body]]
*   [[Loops/Infinite]]
*   [[Loops/N plus one half]]
*   [[Loops/Nested]]
*   [[Loops/While]]
*   [[Loops/with multiple ranges]]
*   [[Loops/Wrong ranges]]
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">L(i) 1..10
I i % 5 == 0
print(i)
L.continue
print(i, end' ‘, ’)</syntaxhighlight>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|360 Assembly}}==
<syntaxhighlight lang="360asm">* 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</syntaxhighlight>
{{out}}
<pre> 1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
=={{header|Ada}}==
Ada doesn't have a continue statement,
Ada 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.
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,
<lang ada>with Ada.Text_Io; use Ada.Text_Io;
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.
 
<syntaxhighlight lang="ada">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 mod= 5 or I = 010 then
New_Line;
goto Continue;
else
Put(",") end if;
end if Put (",");
<<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.
 
<syntaxhighlight lang="ada">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;</syntaxhighlight>
 
=={{header|Agena}}==
Agena doesn't have a continue statement, conditional statements can be used instead.
<syntaxhighlight lang="agena">for i to 10 do
write( i );
if i % 5 = 0
then write( "\n" )
else write( ", " )
fi
od</syntaxhighlight>
 
=={{header|Aikido}}==
<langsyntaxhighlight lang="aikido">foreach i 1..10 {
print (i)
if ((i % 5) == 0) {
Line 30 ⟶ 159:
}
print (", ")
}</langsyntaxhighlight>
 
=={{header|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'''
{{out}}
<pre>
+1 , +2 , +3 , +4 , +5
+6 , +7 , +8 , +9 , +10
</pre>
 
=={{header|ALGOL 68}}==
Line 37 ⟶ 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]}}
[[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:
<langsyntaxhighlight lang="algol68">FOR i FROM 1 TO 10 DO
print ((i,
IF i MOD 5 = 0 THEN
Line 45 ⟶ 191:
FI
))
OD</langsyntaxhighlight>
{{Out}}
Output:
<pre>
+1, +2, +3, +4, +5
+6, +7, +8, +9, +10
</pre>
 
=={{header|ALGOL W}}==
Algol W doesn't have a continue statement - conditional statements can be used instead.
<syntaxhighlight lang="algolw">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.</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}}==
 
<syntaxhighlight lang="rebol">loop 1..10 'i [
prints i
if 0 = i%5 [
print ""
continue
]
prints ", "
]</syntaxhighlight>
 
{{out}}
 
<pre>1, 2, 3, 4, 5
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}}==
<langsyntaxhighlight lang="autohotkey">Loop, 10 {
Delimiter := (A_Index = 5) || (A_Index = 10) ? "`n":", "
Index .= A_Index . Delimiter
}
MsgBox %Index%</langsyntaxhighlight>
 
=={{header|AWK}}==
<langsyntaxhighlight lang="awk">BEGIN {
for(i=1; i <= 10; i++) {
printf("%d", i)
Line 69 ⟶ 275:
printf(", ")
}
}</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic"> 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</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}}===
BBC BASIC doesn't have a 'continue' statement so the remainder of the loop must be made conditional.
<langsyntaxhighlight lang="bbcbasic"> FOR i% = 1 TO 10
PRINT ; i% ;
IF i% MOD 5 = 0 PRINT ELSE PRINT ", ";
NEXT</langsyntaxhighlight>
 
==={{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.
<syntaxhighlight lang="qbasic">10 FOR I = 1 to 10
20 PRINT I;
30 IF INT(I/5) = I/5 THEN PRINT : GOTO 50
40 PRINT ", ";
50 NEXT</syntaxhighlight>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="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</syntaxhighlight>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="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</syntaxhighlight>
 
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">
for i =1 to 10
if i mod 5 <>0 then print i; ", "; else print i
next i
end
</syntaxhighlight>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">OpenConsole()
 
For i.i = 1 To 10
Print(Str(i))
If i % 5 = 0
PrintN("")
Continue
EndIf
Print(",")
Next
 
Repeat: Until Inkey() <> ""</syntaxhighlight>
 
==={{header|QB64}}===
<syntaxhighlight lang="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</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|QBasic}}
<syntaxhighlight lang="runbasic">for i = 1 to 10
if i mod 5 <> 0 then print i;", "; else print i
next i</syntaxhighlight>
 
==={{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>.
<syntaxhighlight lang="text">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</syntaxhighlight>
 
==={{header|TI-89 BASIC}}===
<syntaxhighlight lang="ti-89">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</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.
 
==={{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}}===
<syntaxhighlight lang="qbasic">
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</syntaxhighlight>
 
==={{header|Visual Basic .NET}}===
<syntaxhighlight lang="vbnet">For i = 1 To 10
Console.Write(i)
If i Mod 5 = 0 Then
Console.WriteLine()
Else
Console.Write(", ")
End If
Next</syntaxhighlight>
 
=={{header|bc}}==
Line 82 ⟶ 447:
 
{{works with|OpenBSD bc}}
<langsyntaxhighlight lang="bc">for (i = 1; i <= 10; i++) {
print i
if (i % 5) {
Line 90 ⟶ 455:
print "\n"
}
quit</langsyntaxhighlight>
 
=={{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}}==
Befunge outputs numbers with a space after them, so the formatting is slightly off in this version.
<syntaxhighlight lang="befunge">
1>:56+\`#v_@
+v %5:.:<
1>#v_55+,v
^ <
>" ,",,v
^ <
</syntaxhighlight>
 
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">
1>:56+\`#v_@
+v5:,8.:<
1>%#v_55+,v
^ <
>" ,",v
^ ,<
</syntaxhighlight>
 
=={{header|Bracmat}}==
Bracmat has no continue statement.
<syntaxhighlight lang="bracmat">( 0:?i
& whl
' ( 1+!i:~>10:?i
& put
$ ( str
$ ( !i
(mod$(!i.5):0&\n|", ")
)
)
)
);</syntaxhighlight>
 
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang="c">for(int i = 1;i <= 10; i++){
printf("%d", i);
if(i % 5 == 0){
Line 101 ⟶ 519:
}
printf(", ");
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{trans|Java}}
<lang cpp>for(int i = 1;i <= 10; i++){
cout << i;
if(i % 5 == 0){
cout << endl;
continue;
}
cout << ", ";
}</lang>
 
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
 
class Program {
Line 131 ⟶ 538:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{trans|Java}}
<syntaxhighlight lang="cpp">for(int i = 1;i <= 10; i++){
cout << i;
if(i % 5 == 0){
cout << endl;
continue;
}
cout << ", ";
}</syntaxhighlight>
 
=={{header|C3}}==
{{trans|Java}}
<syntaxhighlight lang="c3">for (int i = 1; i <= 10; i++)
{
io::print(i);
if (i % 5 == 0)
{
io::printn();
continue;
}
io::print(", ");
}</syntaxhighlight>
 
=={{header|Chapel}}==
<langsyntaxhighlight lang="chapel">for i in 1..10 {
write(i);
if i % 5 == 0 then {
Line 141 ⟶ 572:
}
write(", ");
}</langsyntaxhighlight>
 
=={{header|Clipper}}==
''LOOP'' keyword is used here instead of ''continue''.
 
Works as is with Harbour 3.0.0 (Rev. 16951)
<syntaxhighlight lang="visualfoxpro">FOR i := 1 TO 10
?? i
IF i % 5 == 0
?
LOOP
ENDIF
?? ", "
NEXT</syntaxhighlight>
 
=={{header|Clojure}}==
Clojure doesn't have a continue keyword. It has a recur keyword, although I prefer to work with ranges in this case.
<langsyntaxhighlight lang="clojure">(doseq [n (range 1 11)]
[n (rangeprint 1 11n)]
(if (zero? (rem n 5))
(do
(print n (println)
(if (= (rem n 5) 0) (print "\n") (print ", "))))</langsyntaxhighlight>
 
To address the task, however, here's an example loop/recur:
<syntaxhighlight lang="clojure">(loop [xs (range 1 11)]
(when-let [x (first xs)]
(print x)
(if (zero? (rem x 5))
(println)
(print ", "))
(recur (rest xs))))</syntaxhighlight>
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. loop-continue.
 
Line 172 ⟶ 625:
 
GOBACK
.</langsyntaxhighlight>
 
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 178 ⟶ 631:
=={{header|ColdFusion}}==
Remove the leading space from the line break tag.
<langsyntaxhighlight lang="cfm"><cfscript>
for( i = 1; i <= 10; i++ )
{
Line 189 ⟶ 642:
writeOutput( "," );
}
</cfscript></langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Common Lisp doesn't have a continue keyword, but the <code>do</code> iteration construct does use an implicit <code>tagbody</code>, so it's easy to <code>go</code> 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 <code>tagbody</code> and <code>go</code>. The third is a do loop with conditionals outside of the output functions.
Four solutions follow.
<lang lisp>(do ((i 1 (1+ i))) ((> i 10))
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 <code>tagbody</code> and <code>go</code>.
The third is a do loop with conditionals outside of the output functions.
<syntaxhighlight lang="lisp">(do ((i 1 (1+ i)))
((> i 10))
(format t "~a~:[, ~;~%~]" i (zerop (mod i 5))))
 
(do ((i 1 (1+ i))) ((> i 10))
((> i 10))
(write i)
(when (zerop (mod i 5))
Line 204 ⟶ 663:
end)
 
(do ((i 1 (1+ i))) ((> i 10))
((> i 10))
(write i)
(if (zerop (mod i 5))
(terpri)
(write-string ", ")))</langsyntaxhighlight>
 
These use the <code>loop</code> 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 <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 first uses an explicit condition to omit the rest of the loop;
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.
 
<langsyntaxhighlight lang="lisp">(loop for i from 1 to 10
do (write i)
if (zerop (mod i 5)) do (terpri)
else do (write-string ", ")terpri)
else
do (write-string ", "))
 
(loop for i from 1 to 10 do
Line 223 ⟶ 687:
(terpri)
(return-from continue))
(write-string ", ")))</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="d">import std.stdio;
 
void main() {
Line 237 ⟶ 718:
write(", ");
}
}</langsyntaxhighlight>
{{out}}
<pre>1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
===Shorter version===
<syntaxhighlight lang="d">
import std.stdio;
 
void main()
{
foreach(i; 1..11) i % 5 ? writef("%s, ", i) : writeln(i);
}
</syntaxhighlight>
 
=={{header|dc}}==
The four commands <tt># n J M</tt> are special to [[OpenBSD dc]]. The <tt>#</tt> command starts a comment. The <tt>n</tt> command prints a number without a newline.
The <tt>#</tt> command starts a comment.
The <tt>n</tt> command prints a number without a newline.
 
{{trans|bc}}
{{works with|OpenBSD dc}}
 
<langsyntaxhighlight lang="dc">1 si # i = 1
[2Q]sA # A = code to break loop
[[, ]P 1J]sB # B = code to print comma, continue loop
Line 259 ⟶ 752:
li 1 + si # i += 1
li 10!<C # continue loop if 10 >= i
]sC li 10!<C # enter loop if 10 >= i</langsyntaxhighlight>
 
This program uses <tt>J</tt> and <tt>M</tt> to force the next iteration of a loop. The <tt>''n''J</tt> command breaks ''n'' levels of brackets (like <tt>''n''Q</tt> does so), but then skips to the next <tt>M</tt> command. One can place <tt>M</tt> at the end of the iteration.
The <tt>''n''J</tt> command breaks ''n'' levels of brackets (like <tt>''n''Q</tt> does so), but then skips to the next <tt>M</tt> command.
One can place <tt>M</tt> at the end of the iteration.
 
=={{header|Delphi}}==
 
<langsyntaxhighlight Delphilang="delphi">program DoLoop(output);
var
i: integer;
Line 279 ⟶ 774:
write(', ');
end;
end.</langsyntaxhighlight>
 
{{Out}}
Output:
<pre>
1, 2, 3, 4, 5
Line 289 ⟶ 784:
=={{header|DWScript}}==
 
<langsyntaxhighlight Delphilang="delphi">var i : Integer;
 
for i := 1 to 10 do begin
Line 298 ⟶ 793:
end;
Print(', ');
end;</langsyntaxhighlight>
 
=={{header|Dyalect}}==
 
{{trans|Swift}}
 
<syntaxhighlight lang="dyalect">for i in 1..10 {
print(i, terminator: "")
if i % 5 == 0 {
print()
continue
}
print(", ", terminator: "")
}</syntaxhighlight>
 
{{out}}
 
<pre>1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
=={{header|Ela}}==
 
===Direct Approach===
<syntaxhighlight lang="ela">open monad io
 
<lang ela>open console imperative
loop n | n > 10 = ()
if n > 10 then do
| else = rec write (show n) f `seq` loop (n+1)
return ()
where f | n % 5 == 0 = "\r\n"
| else = ", "do
putStr (show n)
putStr f
loop 1</lang>
loop (n + 1)
where f | n % 5 == 0 = "\r\n"
| else = ", "
 
_ = loop 1 ::: IO</syntaxhighlight>
Function rec creates a cyclic version of a given function, it is defined in imperative module as 'rec f x = f x `seq` rec f' where 'seq' is a sequencing operator.
 
===Using list===
<syntaxhighlight lang="ela">open monad io
 
<lang ela>open console imperative
loop [] = return ()
loop (x::xs) = rec (write << show) x c `seq` loop xsdo
putStr (show x)
where c | x % 5 == 0 = "\r\n"
putStr f
| else = ", "
loop xs
where f | x % 5 == 0 = "\r\n"
| else = ", "
_ = loop [1..10] ::: IO</langsyntaxhighlight>
 
This version is more generic and can work for any given range of values.
 
=={{header|Elixir}}==
<syntaxhighlight lang="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</syntaxhighlight>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
for int i = 1; i <= 10; ++i
write(i)
if i % 5 == 0
writeLine()
continue
end
write(", ")
end
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="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.
</syntaxhighlight>
</lang>
{{out}}
<pre>1, 2, 3, 4, 5
6, 7, 8, 9, 10
ok</pre>
 
=={{header|ERRE}}==
<syntaxhighlight lang="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
</syntaxhighlight>
 
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.3, 4.0.0 or later}}
<langsyntaxhighlight lang="euphoria">include std\console.e --only for any_key to make running command window easier on windows
 
for i = 1 to 10 do
Line 368 ⟶ 934:
end if
end for
any_key()</langsyntaxhighlight>
Version without newline after 10 below.
<langsyntaxhighlight lang="euphoria">include std\console.e --only for any_key to make running command window easier on windows
 
for i = 1 to 10 do
Line 388 ⟶ 954:
end for
any_key()
</syntaxhighlight>
</lang>
 
=={{header|F Sharp|F#}}==
<code>continue</code> is a reserved word, but it has no function. 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
if i % 5 = 0 then
printf "\n"
else
printf ", "</langsyntaxhighlight>
===Using [[Comma quibbling#The Function]]===
<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
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)
</syntaxhighlight>
{{out}}
<pre>
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
</pre>
 
=={{header|Factor}}==
There is no built-in <code>continue</code> in Factor.
<langsyntaxhighlight lang="factor">1 10 [a,b] [
[ number>string write ]
[ 5 mod 0 = "\n" ", " ? write ] bi
] each</langsyntaxhighlight>
 
=={{header|Fantom}}==
Line 411 ⟶ 997:
While and for loops support <code>continue</code> to jump back to begin the next iteration of the loop.
 
<langsyntaxhighlight lang="fantom">
class LoopsContinue
{
Line 429 ⟶ 1,015:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
Although this code solves the task, there is no portable equivalent to "continue" for either DO-LOOPs or BEGIN loops.
<langsyntaxhighlight lang="forth">: main
11 1 do
i dup 1 r.
5 mod 0= if cr else [char] , emit space then
loop ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">do i = 1, 10
write(*, '(I0)', advance='no') i
if ( mod(i, 5) == 0 ) then
Line 448 ⟶ 1,034:
end if
write(*, '(A)', advance='no') ', '
end do</langsyntaxhighlight>
 
{{works with|Fortran|77 and later}}
<langsyntaxhighlight 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 compilers should be okay with it, but it is *not* standard.
Line 517 ⟶ 1,103:
5001 FORMAT (I3, ',', $)
C5001 FORMAT (I3, ',', ADVANCE='NO')
END</langsyntaxhighlight>
 
===Relying instead upon the looping features of FORMAT===
For historical reasons, 6 is often the default unit number for standard output.
<syntaxhighlight lang="fortran">
WRITE (6,1) (I,I = 1,10)
1 FORMAT (4(1X,I0,","),1X,I0)
END
</syntaxhighlight>
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.
 
=={{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}}==
'''[https://gambas-playground.proko.eu/?gist=bf629ae9a09ffa1f5ecc95b89854b14b Click this link to run this code]'''
<syntaxhighlight lang="gambas">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</syntaxhighlight>
Output:
<pre>
1,2,3,4,5
6,7,8,9,10
</pre>
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap">for i in [1 .. 11] do
if RemInt(i, 5) = 0 then
Print(i, "\n");
Line 529 ⟶ 1,164:
 
# 1, 2, 3, 4, 5
# 6, 7, 8, 9, 10</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight GMLlang="gml">for(i = 1; i <= 10; i += 1)
{
show_message(string(i))
Line 538 ⟶ 1,192:
if(i <= 10)
continue
}</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 554 ⟶ 1,208:
fmt.Printf(", ")
}
}</langsyntaxhighlight>
{{Out}}
Output:
<pre>
1, 2, 3, 4, 5
Line 562 ⟶ 1,216:
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">for (i in 1..10) {
print i
if (i % 5 == 0) {
Line 569 ⟶ 1,223:
}
print ', '
}</langsyntaxhighlight>
 
=={{header|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.
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.
 
<langsyntaxhighlight lang="haskell">import Control.Monad (forM)
main = forM [1..10] out
where
out x | x `mod` 5 == 0 = print x
| otherwise = (putStr . (++", ") . show) x</langsyntaxhighlight>
 
=={{header|Haxe}}==
<syntaxhighlight lang="haxe">for (i in 1...11) {
Sys.print(i);
if (i % 5 == 0) {
Sys.print('\n');
continue;
}
Sys.print(', ');
}</syntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">DO i = 1, 10
IF( MOD(i, 5) == 1 ) THEN
WRITE(Format="i3") i
Line 587 ⟶ 1,252:
WRITE(APPend, Format=" ',', i3 ") i
ENDIF
ENDDO </langsyntaxhighlight>
 
== {{header|Icon}} and {{header|Unicon}} ==
The following code demonstrates the use of 'next' (the reserved word for 'continue'):
<langsyntaxhighlight Iconlang="icon">procedure main()
every writes(x := 1 to 10) do {
if x % 5 = 0 then {
Line 599 ⟶ 1,264:
writes(", ")
}
end</langsyntaxhighlight>
However, the output sequence can be written without 'next' and far more succinctly as:
<langsyntaxhighlight Iconlang="icon">every writes(x := 1 to 10, if x % 5 = 0 then "\n" else ", ")</langsyntaxhighlight>
 
=={{header|Io}}==
<syntaxhighlight lang="io">for(i,1,10,
write(i)
if(i%5 == 0, writeln() ; continue)
write(" ,")
)</syntaxhighlight>
 
=={{header|J}}==
J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way:
For example, one could satisfy this task this way:
 
<langsyntaxhighlight lang="j">_2}."1'lq<, >'8!:2>:i.2 5</langsyntaxhighlight>
 
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=.''
for_i. 1 + i.y do.
Line 623 ⟶ 1,297:
end.
i.0 0
)</langsyntaxhighlight>
 
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}}==
<langsyntaxhighlight lang="java">for(int i = 1;i <= 10; i++){
System.out.print(i);
if(i % 5 == 0){
Line 635 ⟶ 1,322:
}
System.out.print(", ");
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Using the <code>print()</code> function from [[Rhino]] or [[SpiderMonkey]].
<langsyntaxhighlight lang="javascript">var output = "";
for (var i = 1; i <= 10; i++) {
output += i;
Line 648 ⟶ 1,335:
}
output += ", ";
}</langsyntaxhighlight>
 
 
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:
 
<syntaxhighlight lang="javascript">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');
}, ''
)
);</syntaxhighlight>
 
Output:
<syntaxhighlight lang="javascript">1, 2, 3, 4, 5
6, 7, 8, 9, 10
</syntaxhighlight>
 
=={{header|jq}}==
jq does not have a "continue" statement.
In jq 1.4, the simplest way to accomplish the given task is probably as follows:
<syntaxhighlight lang="jq">reduce range(1;11) as $i
(""; . + "\($i)" + (if $i % 5 == 0 then "\n" else ", " end))</syntaxhighlight>
 
=={{header|Jsish}}==
<syntaxhighlight lang="javascript">/* Loop/continue in jsish */
for (var i = 1; i <= 10; i++) {
printf("%d", i);
if (i % 5 == 0) {
printf("\n");
continue;
}
printf(", ");
}</syntaxhighlight>
 
{{out}}
<pre>prompt$ jsish loop-continue.jsi
1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
for i in 1:10
print(i)
if i%5 == 0
println()
continue
end
print(", ")
end
</syntaxhighlight>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.1.2
 
fun main(args: Array<String>) {
for(i in 1 .. 10) {
if (i % 5 == 0) {
println(i)
continue
}
print("$i, ")
}
}</syntaxhighlight>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{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)
</syntaxhighlight>
 
=={{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}}==
<syntaxhighlight lang="langur">for .i of 10 {
write .i
if .i div 5 { writeln(); next }
write ", "
}</syntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">loop(10) => {^
loop_count
loop_count % 5 ? ', ' | '\r'
loop_count < 100 ? loop_continue
'Hello, World!' // never gets executed
^}</langsyntaxhighlight>
 
=={{header|Liberty BASICLDPL}}==
<syntaxhighlight lang="ldpl">data:
<lang lb>
i is number
for i =1 to 10
n is number
if i mod 5 <>0 then print i; ", "; else print i
 
next i
procedure:
end
for i from 1 to 11 step 1 do
</lang>
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}}==
<syntaxhighlight lang="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</syntaxhighlight>
 
=={{header|Lisaac}}==
<langsyntaxhighlight Lisaaclang="lisaac">1.to 10 do { i : INTEGER;
i.print;
(i % 5 = 0).if { '\n'.print; } else { ','.print; };
};</langsyntaxhighlight>
 
=={{header|LiveCode}}==
<syntaxhighlight lang="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</syntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">for i = 1, 10 do
io.write( i )
if i % 5 == 0 then
Line 680 ⟶ 1,524:
io.write( ", " )
end
end</langsyntaxhighlight>
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}}==
<syntaxhighlight lang="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
</syntaxhighlight>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">for i from 1 to 10 do
printf( "%d", i );
if irem( i, 5 ) = 0 then
Line 690 ⟶ 1,584:
end if;
printf( ", " )
end do:</langsyntaxhighlight>
 
This can also be done as follows, but without the use of "next".
<langsyntaxhighlight Maplelang="maple">for i to 10 do
printf( "%d%s", i, `if`( irem( i, 5 ) = 0, "\n", ", " ) )
end do:</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">tmp = "";
For[i = 1, i <= 10, i++,
tmp = tmp <> ToString[i];
Line 706 ⟶ 1,601:
];
];
Print[tmp]</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|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
<langsyntaxhighlight Matlablang="matlab">disp(reshape([1:10],5,2)')</langsyntaxhighlight>
 
A non-vectorized version of the code is shown below in Octave
 
<langsyntaxhighlight Matlablang="matlab">for i = 1:10
printf(' %2d', i);
if ( mod(i, 5) == 0 )
Line 723 ⟶ 1,619:
continue
end
end</langsyntaxhighlight>
 
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">/* There is no "continue" in Maxima, the easiest is using a "if" instead */
block(
[s: ""],
Line 739 ⟶ 1,634:
)
)
)$</langsyntaxhighlight>
Using sprint and newline
<syntaxhighlight lang="maxima">
for n:1 thru 10 do (
sprint(n),
if n=5 then newline())$
</syntaxhighlight>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">for i in 1 to 10 do
(
format "%" i
Line 751 ⟶ 1,652:
) continue
format ", "
)</langsyntaxhighlight>
<nowiki>Insert non-formatted text here</nowiki>
 
=={{header|Metafont}}==
Metafont has no a <tt>continue</tt> (or similar) keyword. 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.
 
<langsyntaxhighlight lang="metafont">string s; s := "";
for i = 1 step 1 until 10:
if i mod 5 = 0:
Line 765 ⟶ 1,667:
fi; endfor
message s;
end</langsyntaxhighlight>
 
Since <tt>message</tt> 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.
we need to build a string and output it at the end,
instead of writing the output step by step.
 
'''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
 
<langsyntaxhighlight lang="metafont">primarydef x mod y = (x-y*floor(x/y)) enddef;</langsyntaxhighlight>
 
=={{header|Modula-3}}==
Modula-3 defines the keyword <tt>RETURN</tt> as an exception, but when it is used with no arguments it works just like <tt>continue</tt> in [[C]].
but when it is used with no arguments it works just like <tt>continue</tt> in [[C]].
 
Note, however, that <tt>RETURN</tt> only works inside a procedure or a function procedure; use <tt>EXIT</tt> otherwise.
a function procedure; use <tt>EXIT</tt> otherwise.
 
Module code and imports are omitted.
<langsyntaxhighlight lang="modula3">FOR i := 1 TO 10 DO
IO.PutInt(i);
IF i MOD 5 = 0 THEN
Line 786 ⟶ 1,692:
END;
IO.Put(", ");
END;</langsyntaxhighlight>
 
=={{header|MOO}}==
<langsyntaxhighlight lang="moo">s = "";
for i in [1..10]
s += tostr(i);
Line 798 ⟶ 1,704:
endif
s += ", ";
endfor</langsyntaxhighlight>
 
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
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(", ");
}</syntaxhighlight>
 
{{out}}
<pre>prompt$ nekoc loops-continue.neko
prompt$ neko loops-continue.n
1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
=={{header|Nemerle}}==
{{trans|C#}}
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
using Nemerle.Imperative;
Line 817 ⟶ 1,751:
}
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
Line 836 ⟶ 1,770:
end i_
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">(for (i 1 10)
(print i)
(if (= 0 (% i 5))
(println)
(print ", ")))</syntaxhighlight>
 
=={{header|Nim}}==
{{trans|Python}}
<syntaxhighlight lang="nim">for i in 1..10:
if i mod 5 == 0:
echo i
continue
stdout.write i, ", "</syntaxhighlight>
 
=={{header|NS-HUBASIC}}==
<syntaxhighlight lang="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</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}}==
<syntaxhighlight lang="objeck">class Continue {
function : Main(args : String[]) ~ Nil {
for(i := 1; i <= 10; i += 1;) {
if(i = 5) {
"{$i}, "->PrintLine();
continue;
};
"{$i}, "->Print();
};
}
}</syntaxhighlight>
 
=={{header|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
print_int i;
Line 851 ⟶ 1,833:
1, 2, 3, 4, 5
6, 7, 8, 9, 10
- : unit = ()</langsyntaxhighlight>
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}}==
<langsyntaxhighlight lang="octave">v = "";
for i = 1:10
v = sprintf("%s%d", v, i);
Line 864 ⟶ 1,847:
endif
v = sprintf("%s, ", v);
endfor</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<syntaxhighlight lang="oforth">: loopCont
| i |
10 loop: i [
i dup print 5 mod ifZero: [ printcr continue ]
"," .
] ;</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}}==
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.
<langsyntaxhighlight lang="oz">for I in 1..10 continue:C do
{System.print I}
if I mod 5 == 0 then
Line 875 ⟶ 1,886:
end
{System.printInfo ", "}
end</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">for(n=1,10,
print1(n);
if(n%5 == 0, print();continue);
print1(", ")
)</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 888 ⟶ 1,899:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">foreach (1..10) {
print $_;
if ($_ % 5 == 0) {
Line 895 ⟶ 1,906:
}
print ', ';
}</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight lang="perl">foreach (1..10) {
print $_;
if ($_ % 5 == 0) {
Line 907 ⟶ 1,919:
print ', ';
MYLABEL:
}</langsyntaxhighlight>
 
=={{header|Perl 6Phix}}==
{{libheader|Phix/basics}}
{{trans|Perl}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
{{works with|Rakudo Star|2010.08}}
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<lang perl6>for 1 .. 10 {
<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>
.print;
<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>
if $_ %% 5 {
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
print "\n";
<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;">"\n"</span><span style="color: #0000FF;">)</span>
next;
<span style="color: #008080;">continue</span>
}
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
print ', ';
<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>
}</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
 
<!--</syntaxhighlight>-->
or without using a loop:
{{out}}
 
<pre>
<lang perl6>$_.join(", ").say for [1..5], [6..10];</lang>
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: #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: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</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;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">else</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;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">for ($i = 1; $i <= 10; $i++) {
echo $i;
if ($i % 5 == 0) {
Line 933 ⟶ 1,960:
}
echo ', ';
}</langsyntaxhighlight>
 
=={{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}}==
PicoLisp doesn't have an explicit 'continue' functionality. It can always be
It can always be emulated with a conditional expression.
<langsyntaxhighlight PicoLisplang="picolisp">(for I 10
(print I)
(if (=0 (% I 5))
(prinl)
(prin ", ") ) )</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">int main(){
for(int i = 1; i <= 10; i++){
write(sprintf("%d",i));
Line 954 ⟶ 2,003:
write(", ");
}
}</langsyntaxhighlight>
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">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;</langsyntaxhighlight>
 
=={{header|Plain English}}==
In Plain English, continue is spelled <code>repeat</code> and is the only way to specify an end of a loop.
<syntaxhighlight lang="plainenglish">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.</syntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">lvars i;
for i from 1 to 10 do
printf(i, '%p');
Line 973 ⟶ 2,038:
endif;
printf(', ')
endfor;</langsyntaxhighlight>
 
=={{header|PowerShell}}==
{{trans|C}}
<langsyntaxhighlight lang="powershell">for ($i = 1; $i -le 10; $i++) {
Write-Host -NoNewline $i
if ($i % 5 -eq 0) {
Line 984 ⟶ 2,049:
}
Write-Host -NoNewline ", "
}</langsyntaxhighlight>
 
=={{header|PureBasicProlog}}==
Prolog doesn't have a continue statement. So I just use a conditional that ends the body of the predicate.
<lang purebasic>OpenConsole()
 
{{works with|GNU Prolog}}
For i.i = 1 To 10
{{works with|SWI Prolog}}
Print(Str(i))
<syntaxhighlight lang="prolog">
If i % 5 = 0
:- initialization(main).
PrintN("")
Continue
EndIf
Print(",")
Next
 
print_list(Min, Max) :-
Repeat: Until Inkey() <> ""</lang>
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}}==
<langsyntaxhighlight lang="python">for i in xrangerange(1, 11):
if i % 5 == 0:
print (i)
continue
print (i, ","end=', ')</langsyntaxhighlight>
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">10 times
[ i^ 1+ dup echo
5 mod 0 = iff
cr done
say ", " ]</syntaxhighlight>
 
=={{header|R}}==
{{trans|C++}}
<langsyntaxhighlight Rlang="r">for(i in 1:10)
{
cat(i)
Line 1,018 ⟶ 2,108:
}
cat(", ")
}</langsyntaxhighlight>
 
=={{header|Racket}}==
 
It is possible to skip loop iterations in Racket, but an explicit <tt>continue</tt> construct is rarely used:
but an explicit <tt>continue</tt> construct is rarely used:
 
<langsyntaxhighlight lang="racket">
#lang racket
 
Line 1,039 ⟶ 2,130:
(printf "~a~n" i)))
(printf "~a, " i))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{trans|Perl}}
{{works with|Rakudo Star|2010.08}}
<syntaxhighlight lang="raku" line>for 1 .. 10 {
.print;
if $_ %% 5 {
print "\n";
next;
}
print ', ';
}</syntaxhighlight>
 
or without using a loop:
 
<syntaxhighlight lang="raku" line>$_.join(", ").say for [1..5], [6..10];</syntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Loop/Continue"
Author: oofoe
Date: 2010-01-05
URL: http://rosettacode.org/wiki/Loop/Continue
]
Line 1,063 ⟶ 2,169:
prin ", "
]
]</langsyntaxhighlight>
 
Output:
 
{{Out}}
<pre>One liner (compare to ALGOL 68 solution):
1, 2, 3, 4, 5
Line 1,074 ⟶ 2,179:
1, 2, 3, 4, 5
6, 7, 8, 9, 10</pre>
 
=={{header|Red}}==
<syntaxhighlight lang="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</syntaxhighlight>
 
=={{header|REXX}}==
===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.)
<langsyntaxhighlight 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 */
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 intinteger.*/
end
say /*force REXX to display toon next line. */
end /*j*/
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
Program note: &nbsp; the comma (<big><b>,</b></big>) immediately after the &nbsp; '''charout''' &nbsp; BIF indicates to use the terminal output stream.
 
<br><br>
'''output'''
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
===version 2===
<syntaxhighlight lang="rexx">/*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. */</syntaxhighlight>
'''output''' &nbsp; is the same as the 1<sup>st</sup> REXX version. <br><br>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
for i = 1 TO 10
see i
if i % 5 = 0
see nl
loop
ok
see ", "
next
</syntaxhighlight>
 
=={{header|RPL}}==
You need an <code>IF..THEN..ELSE</code> structure to do that in RPL.
« ""
1 10 '''FOR''' j
j +
'''IF''' j 5 MOD '''THEN''' ", " + '''ELSE''' "" '''END'''
'''NEXT''' DROP
» '<span style="color:blue">TASK</span>' STO
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">for i in 1..10 do
print i
if i % 5 == 0 then
Line 1,099 ⟶ 2,251:
end
print ', '
end</langsyntaxhighlight>
The "for" look could be written like this:
<langsyntaxhighlight lang="ruby">(1..10).each do |i| ...
1.upto(10) do |i| ...
10.times do |n| i=n+1; ...</langsyntaxhighlight>
Without meeting the criteria (showing loop continuation), this task could be written as:
<syntaxhighlight lang ="ruby">(1.upto(.10) .each_slice(5){|iar| printputs ar.join("%d%s" % [i, i%5==0 ? "\n" : ", "])}</langsyntaxhighlight>
 
=={{header|Run BASICRust}}==
<syntaxhighlight lang="rust">fn main() {
<lang runbasic>for i = 1 to 10
for i in 1..=10 {
if i mod 5 <> 0 then print i;", "; else print i
print!("{}", i);
next i</lang>
if i % 5 == 0 {
println!();
continue;
}
print!(", ");
}
}</syntaxhighlight>
 
=={{header|Salmon}}==
<langsyntaxhighlight Salmonlang="salmon">iterate (x; [1...10])
{
print(x);
Line 1,122 ⟶ 2,281:
};
print(", ");
};</langsyntaxhighlight>
 
=={{header|Sather}}==
There's no <code>continue!</code> in Sather. The code solve the task without forcing a new iteration.
<langsyntaxhighlight lang="sather">class MAIN is
main is
i:INT;
Line 1,138 ⟶ 2,297:
end;
end;
end;</langsyntaxhighlight>
 
=={{header|Scala}}==
Scala doesn't have a <code>continue</code> keyword.
[[Category:Scala Implementations]]
Scala doesn't have a <code>continue</code> keyword. However, you may not even miss it, <code>if</code> could be used here.
 
===The intuitive way===
<langsyntaxhighlight lang="scala">for (i <- 1 to 10) {
print(i)
if (i % 5 == 0) println() else print(", ")
}</langsyntaxhighlight>
 
===Functional solution===
Thinking In Scala<sup>©</sup> says: we avoid for loops and handle it the [[functional_programming|Functional]] way:
Line 1,155 ⟶ 2,316:
#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
<langsyntaxhighlight 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.*/ )</langsyntaxhighlight>
 
=={{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
(beginscheme write))
 
(display i)
(define (loop-fn start end)
(cond ((zero? (modulo i 5))
(newline)define (loop (+ 1 i)))
(elseif (display> ",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}}==
{{works with|Scilab|5.5.1}}
<syntaxhighlight lang="text">for i=1:10
printf("%2d ",i)
if modulo(i,5)~=0 then
printf(", ")
continue
end
printf("\n")
end </syntaxhighlight>
{{out}}
<pre> 1 , 2 , 3 , 4 , 5
6 , 7 , 8 , 9 , 10 </pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">for i in (1..10) {
print i
if (i %% 5) {
print "\n"
next
}
print ', '
}</syntaxhighlight>
 
=={{header|Simula}}==
{{works with|SIMULA-67}}
<syntaxhighlight lang="simula">! 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</syntaxhighlight>
{{out}}
<pre>
    1,     2,     3,     4,     5
    6,     7,     8,     9,    10
</pre>
 
=={{header|Smalltalk}}==
{{works with|Pharo}} {{works with|Smalltalk/X}} actually works with all dialects &sup1;
<syntaxhighlight lang="smalltalk">
1 to: 10 do: [ :i |
[ :continue |
i % 5 = 0 ifTrue: [
Transcript show: i; cr.
continue value ].
Transcript
show: i;
show: ', '.
] valueWithExit.
]
</syntaxhighlight>
&sup1; if valueWithExit is not present in the Block class, it can be added as:
<syntaxhighlight lang="smalltalk">valueWithExit
^ self value:[^ nil]</syntaxhighlight>
 
=={{header|SNOBOL4}}==
 
SNOBOL4 has no looping statements or conditional statements. Indeed the only branching facilities it has are:
 
* Unconditional branch to label. <code>:(LABEL)</code>
* Branch to label on success. <code>:S(LABEL)</code>
* Branch to label on failure. <code>:F(LABEL)</code>
 
(The success/failure labels can both be in the branching clause.)
 
Despite this, any looping structure can be performed by careful use of these.
 
<syntaxhighlight lang="snobol4">
line =
i = 1
LOOP le(i, 10) :F(LOOP.END)
line = line i
eq(remdr(i, 5), 0) :S(LOOP.OUT)
line = line ', ' :(LOOP.INC)
LOOP.OUT OUTPUT = line
line =
LOOP.INC i = i + 1 :(LOOP)
LOOP.END OUTPUT = line
 
END
</syntaxhighlight>
 
{{Out}}
 
<pre>
$ snobol4 junk.sno
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Spin}}==
{{works with|BST/BSTC}}
{{works with|FastSpin/FlexSpin}}
{{works with|HomeSpun}}
{{works with|OpenSpin}}
<syntaxhighlight lang="spin">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)</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|SPL}}==
<syntaxhighlight lang="spl">> n, 1..10
s += n
? n%5, s += ", "
>> n%5
#.output(s)
s = ""
<</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|SQL PL}}==
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<syntaxhighlight lang="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 @
</syntaxhighlight>
Output:
<pre>
db2 => BEGIN
...
db2 (cont.) => END @
DB20000I The SQL command completed successfully.
 
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Stata}}==
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.
 
<syntaxhighlight lang="stata">forvalues n=1/10 {
display `n' _continue
if mod(`n',5)==0 {
display
continue
}
display ", " _continue
}</syntaxhighlight>
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">ob = Object()
for (i = 1; i <= 10; ++i)
{
Line 1,179 ⟶ 2,537:
}
}
Print(ob.Join(','))</langsyntaxhighlight>
 
{{Out}}
Output:
<langsyntaxhighlight Suneidolang="suneido">1,2,3,4,5
6,7,8,9,10
ok</langsyntaxhighlight>
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">for i in 1...10 {
print(i, terminator: "")
if i % 5 == 0 {
print()
continue
}
print(", ", terminator: "")
}</syntaxhighlight>
{{Out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">for {set i 1} {$i <= 10} {incr i} {
puts -nonewline $i
if {$i % 5 == 0} {
Line 1,194 ⟶ 2,567:
}
puts -nonewline ", "
}</langsyntaxhighlight>
 
=={{header|TITransact-89 BASICSQL}}==
<lang ti-89>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</lang>
 
<syntaxhighlight lang="transact-sql">
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.
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;
</syntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
numbers=""
Line 1,224 ⟶ 2,599:
numbers=""
ENDLOOP
</syntaxhighlight>
</lang>
{{Out}}
Output:
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|UnixPipes}}==
<lang bash>yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,</lang>
 
=={{header|UNIX Shell}}==
<langsyntaxhighlight lang="bash">Z=1
while (( Z<=10 )); do
echo -e "$Z\c"
Line 1,244 ⟶ 2,616:
fi
(( Z++ ))
done</langsyntaxhighlight>
 
{{works with|Bash}}
<langsyntaxhighlight lang="bash">for ((i=1;i<=10;i++)); do
echo -n $i
if [ $((i%5)) -eq 0 ]; then
Line 1,254 ⟶ 2,626:
fi
echo -n ", "
done</langsyntaxhighlight>
 
=={{header|UnixPipes}}==
<syntaxhighlight lang="bash">yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,</syntaxhighlight>
 
=={{header|Ursa}}==
{{trans|Python}}
<syntaxhighlight lang="ursa">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</syntaxhighlight>
 
=={{header|Vala}}==
<syntaxhighlight lang="vala">for (int i = 1; i <= 10; i++) {
stdout.printf("%d", i);
if (i % 5 == 0) {
stdout.printf("\n");
continue;
}
stdout.printf(", ");
}</syntaxhighlight>
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">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</syntaxhighlight>
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">for (#1 = 1; #1 <= 10; #1++) {
Num_Type(#1, LEFT+NOCR)
if (#1 % 5 == 0) {
Line 1,264 ⟶ 2,674:
}
Message(", ")
}</langsyntaxhighlight>
 
=={{header|VisualV Basic .NET(Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
<lang vbnet>For i = 1 To 10
for i in 1..11 {
Console.Write(i)
If i Mod 5 = 0 Thenprint(i)
Console.WriteLine()if i%5==0{
println('')
Else
Console.Write(", ") continue
End If }
print(', ')
Next</lang>
}
}</syntaxhighlight>
{{Out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|Wren}}==
From v0.4.0 Wren has a ''continue'' keyword which works in the expected fashion.
<syntaxhighlight lang="wren">for (i in 1..10) {
System.write(i)
if (i%5 == 0) {
System.print()
continue
}
System.write(", ")
}
 
System.print()</syntaxhighlight>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|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.
<syntaxhighlight lang="asm">
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
</syntaxhighlight>
{{Out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|XBasic}}==
{{works with|Windows XBasic}}
<syntaxhighlight lang="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
</syntaxhighlight>
{{Out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|XPL0}}==
Line 1,281 ⟶ 2,844:
Only the first three characters of a command are required.
 
<langsyntaxhighlight XPL0lang="xpl0">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)]</langsyntaxhighlight>
 
{{Out}}
Output:
<pre>
1, 2, 3, 4, 5
Line 1,292 ⟶ 2,855:
</pre>
 
{{omit from|GUISS}}
{{omit from|M4}}
 
=={{header|Yabasic}}==
[[Category:Loop modifiers]]
<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}}==
<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")}</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>
1,150

edits