Loops/Continue: Difference between revisions
Content added Content deleted
Underscore (talk | contribs) (Added Perl 6.) |
m (Fixed lang tags.) |
||
Line 8: | Line 8: | ||
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. |
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. |
||
<lang ada> |
<lang ada>with Ada.Text_Io; use Ada.Text_Io; |
||
with Ada.Text_Io; use Ada.Text_Io; |
|||
procedure Loop_Continue is |
procedure Loop_Continue is |
||
Line 21: | Line 20: | ||
end if; |
end if; |
||
end loop; |
end loop; |
||
end Loop_Continue; |
end Loop_Continue;</lang> |
||
⚫ | |||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
[[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: |
||
⚫ | |||
<pre> |
|||
⚫ | |||
print ((i, |
print ((i, |
||
IF i MOD 5 = 0 THEN |
IF i MOD 5 = 0 THEN |
||
Line 34: | Line 31: | ||
FI |
FI |
||
)) |
)) |
||
OD |
OD</lang> |
||
</pre> |
|||
Output: |
Output: |
||
⚫ | |||
<pre> |
|||
+ |
+6, +7, +8, +9, +10</lang> |
||
⚫ | |||
</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<lang autohotkey> |
<lang autohotkey>Loop, 10 { |
||
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% |
MsgBox %Index%</lang> |
||
⚫ | |||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
Line 108: | Line 100: | ||
=={{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> |
|||
for( i = 1; i <= 10; i++ ) |
|||
{ |
|||
writeOutput( i ); |
|||
if( 0 == i % 5 ) |
|||
{ |
|||
writeOutput( "< br />" ); |
|||
continue; |
|||
} |
|||
writeOutput( "," ); |
|||
} |
|||
</cfscript></lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Line 179: | Line 171: | ||
=={{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> |
<lang forth>: main |
||
: 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 ; |
loop ;</lang> |
||
⚫ | |||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Line 202: | Line 192: | ||
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. |
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. |
||
<lang haskell> |
<lang haskell>import Control.Monad (forM) |
||
import Control.Monad (forM) |
|||
main = forM [1..10] out |
main = forM [1..10] out |
||
where |
where |
||
Line 215: | Line 204: | ||
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). |
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). |
||
⚫ | |||
<pre> |
|||
⚫ | |||
z=.'' |
z=.'' |
||
for_i. 1 + i.y do. |
for_i. 1 + i.y do. |
||
Line 230: | Line 218: | ||
end. |
end. |
||
i.0 0 |
i.0 0 |
||
) |
)</lang> |
||
</pre> |
|||
Though it's rare to see J code like this. |
Though it's rare to see J code like this. |
||
Line 261: | Line 248: | ||
=={{header|Lisaac}}== |
=={{header|Lisaac}}== |
||
<lang Lisaac> |
<lang Lisaac>1.to 10 do { i : INTEGER; |
||
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> |
||
</lang> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |
||
<lang Mathematica> |
<lang Mathematica>tmp = ""; |
||
tmp = ""; |
|||
For[i = 1, i <= 10, i++, |
For[i = 1, i <= 10, i++, |
||
tmp = tmp <> ToString[i]; |
tmp = tmp <> ToString[i]; |
||
Line 279: | Line 263: | ||
]; |
]; |
||
]; |
]; |
||
Print[tmp] |
Print[tmp]</lang> |
||
</lang> |
|||
=={{header|MAXScript}}== |
=={{header|MAXScript}}== |
||
⚫ | |||
<pre> |
|||
⚫ | |||
( |
( |
||
format "%" i |
format "%" i |
||
Line 293: | Line 275: | ||
) continue |
) continue |
||
format ", " |
format ", " |
||
⚫ | |||
) |
|||
</pre> |
|||
=={{header|Metafont}}== |
=={{header|Metafont}}== |
||
Line 322: | Line 303: | ||
Module code and imports are omitted. |
Module code and imports are omitted. |
||
⚫ | |||
<pre> |
|||
⚫ | |||
IO.PutInt(i); |
IO.PutInt(i); |
||
IF i MOD 5 = 0 THEN |
IF i MOD 5 = 0 THEN |
||
Line 330: | Line 310: | ||
END; |
END; |
||
IO.Put(", "); |
IO.Put(", "); |
||
END; |
END;</lang> |
||
</pre> |
|||
=={{header|MOO}}== |
=={{header|MOO}}== |
||
Line 408: | Line 387: | ||
=={{header|Pop11}}== |
=={{header|Pop11}}== |
||
<lang pop11>lvars i; |
|||
<pre> |
|||
lvars i; |
|||
for i from 1 to 10 do |
for i from 1 to 10 do |
||
printf(i, '%p'); |
printf(i, '%p'); |
||
Line 417: | Line 395: | ||
endif; |
endif; |
||
printf(', ') |
printf(', ') |
||
endfor; |
endfor;</lang> |
||
</pre> |
|||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
Line 440: | Line 417: | ||
=={{header|R}}== |
=={{header|R}}== |
||
Translated from C++. |
Translated from C++. |
||
<lang R> |
<lang R>for(i in 1:10) |
||
for(i in 1:10) |
|||
{ |
{ |
||
cat(i) |
cat(i) |
||
Line 450: | Line 426: | ||
} |
} |
||
cat(", ") |
cat(", ") |
||
⚫ | |||
} |
|||
</lang> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 490: | Line 465: | ||
=={{header|UnixPipes}}== |
=={{header|UnixPipes}}== |
||
<lang bash>yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,</lang> |
|||
=={{header|Vedit macro language}}== |
=={{header|Vedit macro language}}== |
||
<lang vedit> |
<lang vedit>for (#1 = 1; #1 <= 10; #1++) { |
||
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 501: | Line 475: | ||
} |
} |
||
Message(", ") |
Message(", ") |
||
⚫ | |||
} |
|||
</lang> |
|||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |