Loops/Continue: Difference between revisions

Content added Content deleted
(Loops/Continue in Asymptote)
m (syntax highlighting fixup automation)
Line 35: Line 35:
{{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 48:


=={{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 79:
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 103:
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 117:
<<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 138:
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 148:
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 158:
}
}
print (", ")
print (", ")
}</lang>
}</syntaxhighlight>


=={{header|ALGOL 60}}==
=={{header|ALGOL 60}}==
Line 182: Line 182:
{{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 190:
FI
FI
))
))
OD</lang>
OD</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 199: Line 199:
=={{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 207:
else writeon( ", " )
else writeon( ", " )
end for_i
end for_i
end.</lang>
end.</syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">
<lang AppleScript>
set table to {return}
set table to {return}
repeat with i from 1 to 10
repeat with i from 1 to 10
Line 220: Line 220:
end repeat
end repeat
return table as string
return table as string
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 231: Line 231:
=={{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 238: Line 238:
]
]
prints ", "
prints ", "
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 247: Line 247:
=={{header|Asymptote}}==
=={{header|Asymptote}}==
Asymptote's control structures are similar to those in C/C++
Asymptote's control structures are similar to those in C/C++
<lang Asymptote>for(int i = 1; i <= 10; ++i) {
<syntaxhighlight lang="asymptote">for(int i = 1; i <= 10; ++i) {
write(i, suffix=none);
write(i, suffix=none);
if(i % 5 == 0) {
if(i % 5 == 0) {
Line 255: Line 255:
write(", ", suffix=none);
write(", ", suffix=none);
}
}
}</lang>
}</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 274: Line 274:
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}}===
==={{header|BASIC256}}===
<lang BASIC256>for i = 1 to 10
<syntaxhighlight lang="basic256">for i = 1 to 10
print string(i);
print string(i);
if i mod 5 = 0 then
if i mod 5 = 0 then
Line 295: Line 295:
next
next
print
print
end</lang>
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 324: Line 324:


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


{{out}}
{{out}}
Line 333: Line 333:


==={{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 340: Line 340:
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 362: Line 362:
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 373: Line 373:
End If
End If
Print ", ";
Print ", ";
Next</lang>
Next</syntaxhighlight>


==={{header|Run BASIC}}===
==={{header|Run BASIC}}===
{{works with|QBasic}}
{{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 403: Line 403:
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}}===
==={{header|True BASIC}}===
<lang basic>FOR i = 1 TO 10
<syntaxhighlight lang="basic">FOR i = 1 TO 10
PRINT STR$(i);
PRINT STR$(i);
IF REMAINDER(i, 5) = 0 THEN
IF REMAINDER(i, 5) = 0 THEN
Line 417: Line 417:
NEXT i
NEXT i
PRINT
PRINT
END</lang>
END</syntaxhighlight>


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


Line 430: Line 430:
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 440: Line 440:
Console.Write(", ")
Console.Write(", ")
End If
End If
Next</lang>
Next</syntaxhighlight>


=={{header|bc}}==
=={{header|bc}}==
Line 446: Line 446:


{{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 454: Line 454:
print "\n"
print "\n"
}
}
quit</lang>
quit</syntaxhighlight>


=={{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 465: Line 465:
>" ,",,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 475: Line 475:
>" ,",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 489: Line 489:
)
)
)
)
);</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 500: Line 500:
}
}
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 519: Line 519:
}
}
}
}
}</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 530: Line 530:
}
}
cout << ", ";
cout << ", ";
}</lang>
}</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 540: Line 540:
}
}
write(", ");
write(", ");
}</lang>
}</syntaxhighlight>


=={{header|Clipper}}==
=={{header|Clipper}}==
Line 546: Line 546:


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 553: Line 553:
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 570: Line 570:
(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 593: Line 593:


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 599: Line 599:
=={{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 610: Line 610:
writeOutput( "," );
writeOutput( "," );
}
}
</cfscript></lang>
</cfscript></syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 618: Line 618:
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 636: Line 636:
(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 642: Line 642:
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 655: Line 655:
(terpri)
(terpri)
(return-from continue))
(return-from continue))
(write-string ", ")))</lang>
(write-string ", ")))</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<lang d>import std.stdio;
<syntaxhighlight lang="d">import std.stdio;


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


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


Line 682: Line 682:
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 692: Line 692:
{{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 703: Line 703:
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 711: Line 711:
=={{header|Delphi}}==
=={{header|Delphi}}==


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


{{Out}}
{{Out}}
Line 735: Line 735:
=={{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 744: Line 744:
end;
end;
Print(', ');
Print(', ');
end;</lang>
end;</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==
Line 750: Line 750:
{{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 757: Line 757:
}
}
print(", ", terminator: "")
print(", ", terminator: "")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 767: Line 767:


===Direct Approach===
===Direct Approach===
<lang ela>open monad io
<syntaxhighlight lang="ela">open monad io
loop n =
loop n =
Line 779: Line 779:
| 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 792: Line 792:
| 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 806: Line 806:
end
end


Loops.continue</lang>
Loops.continue</syntaxhighlight>


{{out}}
{{out}}
Line 815: Line 815:


=={{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 836: Line 836:
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 843: Line 843:


=={{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 854: Line 854:
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 868: Line 868:
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 888: Line 888:
end for
end for
any_key()
any_key()
</syntaxhighlight>
</lang>


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
Line 894: Line 894:
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 907: Line 907:
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 922: Line 922:
=={{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 931: Line 931:
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 949: Line 949:
}
}
}
}
</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 968: Line 968:
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 1,037: Line 1,037:
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 1,056: Line 1,056:


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


long num
long num
Line 1,068: Line 1,068:
next
next


HandleEvents</lang>
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,081: Line 1,081:
Next
Next


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


=={{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,098: Line 1,098:


# 1, 2, 3, 4, 5
# 1, 2, 3, 4, 5
# 6, 7, 8, 9, 10</lang>
# 6, 7, 8, 9, 10</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,107: Line 1,107:
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,123: Line 1,123:
fmt.Printf(", ")
fmt.Printf(", ")
}
}
}</lang>
}</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 1,131: Line 1,131:


=={{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,138: Line 1,138:
}
}
print ', '
print ', '
}</lang>
}</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 1,144: Line 1,144:
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,158: Line 1,158:
}
}
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,167: Line 1,167:
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,179: Line 1,179:
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,194: Line 1,194:
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,212: Line 1,212:
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|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,224: Line 1,224:
}
}
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,237: Line 1,237:
}
}
output += ", ";
output += ", ";
}</lang>
}</syntaxhighlight>




Line 1,244: Line 1,244:
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,254: Line 1,254:
}, ''
}, ''
)
)
);</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,276: Line 1,276:
}
}
printf(", ");
printf(", ");
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,284: Line 1,284:


=={{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,293: Line 1,293:
print(", ")
print(", ")
end
end
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,302: Line 1,302:


=={{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,312: Line 1,312:
print("$i, ")
print("$i, ")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,321: Line 1,321:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang="scheme">
{def loops_continue
{def loops_continue
{lambda {:i}
{lambda {:i}
Line 1,334: Line 1,334:
-> 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|langur}}==
=={{header|langur}}==
{{works with|langur|0.8.1}}
{{works with|langur|0.8.1}}
<lang langur>for .i of 10 {
<syntaxhighlight 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|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,362: Line 1,362:
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,385: Line 1,385:
io.write( ", " )
io.write( ", " )
end
end
end</lang>
end</syntaxhighlight>
or
or
<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,395: Line 1,395:
io.write( ", " )
io.write( ", " )
::continue::
::continue::
end</lang>
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,435: Line 1,435:
}
}
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,445: Line 1,445:
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,462: Line 1,462:
];
];
];
];
Print[tmp]</lang>
Print[tmp]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
Line 1,468: Line 1,468:
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,480: Line 1,480:
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,495: Line 1,495:
)
)
)
)
)$</lang>
)$</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,507: Line 1,507:
) continue
) continue
format ", "
format ", "
)</lang>
)</syntaxhighlight>
<nowiki>Insert non-formatted text here</nowiki>
<nowiki>Insert non-formatted text here</nowiki>


Line 1,514: Line 1,514:
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,522: Line 1,522:
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,530: Line 1,530:
'''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,540: Line 1,540:


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,547: Line 1,547:
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,559: Line 1,559:
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,581: Line 1,581:
}
}
$print(", ");
$print(", ");
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,591: Line 1,591:
=={{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,606: Line 1,606:
}
}
}
}
}</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,625: Line 1,625:
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|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,660: Line 1,660:
};
};
}
}
}</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,676: Line 1,676:
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,690: Line 1,690:
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}}==
=={{header|Ol}}==
We use continuation to break the execution of the inner body.
We use continuation to break the execution of the inner body.
<lang scheme>
<syntaxhighlight lang="scheme">
(let loop ((i 1))
(let loop ((i 1))
(when (less? i 11)
(when (less? i 11)
Line 1,713: Line 1,713:
(display ", ")))
(display ", ")))
(loop (+ i 1))))
(loop (+ i 1))))
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 1,722: Line 1,722:
=={{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,729: Line 1,729:
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,742: Line 1,742:


=={{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,749: Line 1,749:
}
}
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,762: Line 1,762:
print ', ';
print ', ';
MYLABEL:
MYLABEL:
}</lang>
}</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/basics}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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>
Line 1,776: Line 1,776:
<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}}
{{out}}
<pre>
<pre>
Line 1,783: Line 1,783:
</pre>
</pre>
The following works just as well, with identical output
The following works just as well, with identical output
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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>
Line 1,793: Line 1,793:
<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,803: Line 1,803:
}
}
echo ', ';
echo ', ';
}</lang>
}</syntaxhighlight>


=={{header|Picat}}==
=={{header|Picat}}==
Line 1,810: Line 1,810:
{{trans|Prolog}}
{{trans|Prolog}}
{{works with|Picat}}
{{works with|Picat}}
<syntaxhighlight lang="picat">
<lang Picat>
main =>
main =>
foreach (I in 1..10)
foreach (I in 1..10)
Line 1,820: Line 1,820:
end,
end,
end.
end.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,830: Line 1,830:
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,846: Line 1,846:
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,870: Line 1,870:
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,881: Line 1,881:
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,892: Line 1,892:
}
}
Write-Host -NoNewline ", "
Write-Host -NoNewline ", "
}</lang>
}</syntaxhighlight>


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


Line 1,919: Line 1,919:
main :-
main :-
print_list(1, 10).
print_list(1, 10).
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,927: Line 1,927:


=={{header|Python}}==
=={{header|Python}}==
<lang python>for i in xrange(1,11):
<syntaxhighlight lang="python">for i in xrange(1,11):
if i % 5 == 0:
if i % 5 == 0:
print i
print i
continue
continue
print i, ",",</lang>
print i, ",",</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,951: Line 1,951:
}
}
cat(", ")
cat(", ")
}</lang>
}</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 1,958: Line 1,958:
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,973: Line 1,973:
(printf "~a~n" i)))
(printf "~a~n" i)))
(printf "~a, " i))
(printf "~a, " i))
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
Line 1,979: Line 1,979:
{{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,986: Line 1,986:
}
}
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 2,012: Line 2,012:
prin ", "
prin ", "
]
]
]</lang>
]</syntaxhighlight>


{{Out}}
{{Out}}
Line 2,024: Line 2,024:


=={{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 2,030: Line 2,030:
]
]
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 2,045: Line 2,045:
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 2,055: Line 2,055:


===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 2,062: Line 2,062:
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 2,075: Line 2,075:
see ", "
see ", "
next
next
</syntaxhighlight>
</lang>


=={{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 2,085: Line 2,085:
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 2,103: Line 2,103:
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 2,115: Line 2,115:
};
};
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 2,131: Line 2,131:
end;
end;
end;
end;
end;</lang>
end;</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
Line 2,138: Line 2,138:


===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 2,150: Line 2,150:
#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}}==
{{incorrect|Scheme|}}
{{incorrect|Scheme|}}
<lang scheme>(define (loop i)
<syntaxhighlight lang="scheme">(define (loop i)
(if (> i 10) 'done
(if (> i 10) 'done
(begin
(begin
Line 2,162: Line 2,162:
(newline) (loop (+ 1 i)))
(newline) (loop (+ 1 i)))
(else (display ", ")
(else (display ", ")
(loop (+ 1 i)))))))</lang>
(loop (+ 1 i)))))))</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,173: Line 2,173:
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,179: Line 2,179:


=={{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,186: Line 2,186:
}
}
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,202: Line 2,202:
loop:
loop:
end
end
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,211: Line 2,211:
=={{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,222: Line 2,222:
] 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|Spin}}==
=={{header|Spin}}==
Line 2,232: Line 2,232:
{{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,251: Line 2,251:
waitcnt(_clkfreq + cnt)
waitcnt(_clkfreq + cnt)
ser.stop
ser.stop
cogstop(0)</lang>
cogstop(0)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,259: Line 2,259:


=={{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,265: Line 2,265:
#.output(s)
#.output(s)
s = ""
s = ""
<</lang>
<</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,275: Line 2,275:
{{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,293: Line 2,293:
END WHILE Loop;
END WHILE Loop;
END @
END @
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 2,308: Line 2,308:
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,315: Line 2,315:
}
}
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,328: Line 2,328:
}
}
}
}
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,343: Line 2,343:
}
}
print(", ", terminator: "")
print(", ", terminator: "")
}</lang>
}</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,351: Line 2,351:


=={{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,358: Line 2,358:
}
}
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,377: Line 2,377:
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,390: Line 2,390:
numbers=""
numbers=""
ENDLOOP
ENDLOOP
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,398: Line 2,398:


=={{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,407: Line 2,407:
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,417: Line 2,417:
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,431: Line 2,431:
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,441: Line 2,441:
}
}
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,455: Line 2,455:
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,465: Line 2,465:
}
}
Message(", ")
Message(", ")
}</lang>
}</syntaxhighlight>


=={{header|Vlang}}==
=={{header|Vlang}}==
<lang vlang>fn main() {
<syntaxhighlight lang="vlang">fn main() {
for i in 1..11 {
for i in 1..11 {
print(i)
print(i)
Line 2,477: Line 2,477:
print(', ')
print(', ')
}
}
}</lang>
}</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,486: Line 2,486:
=={{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="ecmascript">for (i in 1..10) {
System.write(i)
System.write(i)
if (i%5 == 0) {
if (i%5 == 0) {
Line 2,495: Line 2,495:
}
}


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


{{out}}
{{out}}
Line 2,510: Line 2,510:
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,598: Line 2,598:
pop ebx
pop ebx
ret
ret
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,607: Line 2,607:
=={{header|XBasic}}==
=={{header|XBasic}}==
{{works with|Windows XBasic}}
{{works with|Windows XBasic}}
<lang xbasic>
<syntaxhighlight lang="xbasic">
PROGRAM "loopcontinue"
PROGRAM "loopcontinue"


Line 2,623: Line 2,623:
END FUNCTION
END FUNCTION
END PROGRAM
END PROGRAM
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,635: Line 2,635:
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,648: Line 2,648:


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang yabasic>for i = 1 to 10
<syntaxhighlight lang="yabasic">for i = 1 to 10
print str$(i);
print str$(i);
if mod(i, 5) = 0 then
if mod(i, 5) = 0 then
Line 2,657: Line 2,657:
next
next
print
print
end</lang>
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}}==
=={{header|Zig}}==
<lang zig>const std = @import("std");
<syntaxhighlight lang="zig">const std = @import("std");


pub fn main() !void {
pub fn main() !void {
Line 2,678: Line 2,678:
try stdout_wr.writeAll(", ");
try stdout_wr.writeAll(", ");
}
}
}</lang>
}</syntaxhighlight>