Jump to content

Loops/Continue: Difference between revisions

m
Fixed lang tags.
(Added Perl 6.)
m (Fixed lang tags.)
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.
 
<lang ada>with Ada.Text_Io; use Ada.Text_Io;
with Ada.Text_Io; use Ada.Text_Io;
 
procedure Loop_Continue is
Line 21 ⟶ 20:
end if;
end loop;
end Loop_Continue;</lang>
</lang>
=={{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:
<lang algol68>FOR i FROM 1 TO 10 DO
<pre>
FOR i FROM 1 TO 10 DO
print ((i,
IF i MOD 5 = 0 THEN
Line 34 ⟶ 31:
FI
))
OD</lang>
</pre>
Output:
<lang algol68>+61, +72, +83, +94, +105
<pre>
+16, +27, +38, +49, +510</lang>
+6, +7, +8, +9, +10
</pre>
 
=={{header|AutoHotkey}}==
<lang autohotkey>Loop, 10 {
Loop, 10 {
Delimiter := (A_Index = 5) || (A_Index = 10) ? "`n":", "
Index .= A_Index . Delimiter
}
MsgBox %Index%</lang>
</lang>
 
=={{header|AWK}}==
Line 108 ⟶ 100:
=={{header|ColdFusion}}==
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}}==
Line 179 ⟶ 171:
=={{header|Forth}}==
Although this code solves the task, there is no portable equivalent to "continue" for either DO-LOOPs or BEGIN loops.
<lang forth>: main
: main
11 1 do
i dup 1 r.
5 mod 0= if cr else [char] , emit space then
loop ;</lang>
</lang>
 
=={{header|Fortran}}==
Line 202 ⟶ 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.
 
<lang haskell>import Control.Monad (forM)
import Control.Monad (forM)
main = forM [1..10] out
where
Line 215 ⟶ 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).
<lang j>3 : 0 ] 10
<pre>
3 : 0 ] 10
z=.''
for_i. 1 + i.y do.
Line 230 ⟶ 218:
end.
i.0 0
)</lang>
</pre>
 
Though it's rare to see J code like this.
Line 261 ⟶ 248:
 
=={{header|Lisaac}}==
<lang Lisaac>1.to 10 do { i : INTEGER;
1.to 10 do { i : INTEGER;
i.print;
(i % 5 = 0).if { '\n'.print; } else { ','.print; };
};</lang>
</lang>
 
=={{header|Mathematica}}==
<lang Mathematica>tmp = "";
tmp = "";
For[i = 1, i <= 10, i++,
tmp = tmp <> ToString[i];
Line 279 ⟶ 263:
];
];
Print[tmp]</lang>
</lang>
 
=={{header|MAXScript}}==
<lang maxscript>for i in 1 to 10 do
<pre>
for i in 1 to 10 do
(
format "%" i
Line 293 ⟶ 275:
) continue
format ", "
)</lang>
)
</pre>
 
=={{header|Metafont}}==
Line 322 ⟶ 303:
 
Module code and imports are omitted.
<lang modula3>FOR i := 1 TO 10 DO
<pre>
FOR i := 1 TO 10 DO
IO.PutInt(i);
IF i MOD 5 = 0 THEN
Line 330 ⟶ 310:
END;
IO.Put(", ");
END;</lang>
</pre>
 
=={{header|MOO}}==
Line 408 ⟶ 387:
 
=={{header|Pop11}}==
<lang pop11>lvars i;
<pre>
lvars i;
for i from 1 to 10 do
printf(i, '%p');
Line 417 ⟶ 395:
endif;
printf(', ')
endfor;</lang>
</pre>
 
=={{header|PowerShell}}==
Line 440 ⟶ 417:
=={{header|R}}==
Translated from C++.
<lang R>for(i in 1:10)
for(i in 1:10)
{
cat(i)
Line 450 ⟶ 426:
}
cat(", ")
}</lang>
}
</lang>
 
=={{header|REXX}}==
Line 490 ⟶ 465:
 
=={{header|UnixPipes}}==
<lang bash>yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,</lang>
 
=={{header|Vedit macro language}}==
<lang vedit>for (#1 = 1; #1 <= 10; #1++) {
for (#1 = 1; #1 <= 10; #1++) {
Num_Type(#1, LEFT+NOCR)
if (#1 % 5 == 0) {
Line 501 ⟶ 475:
}
Message(", ")
}</lang>
}
</lang>
 
=={{header|Visual Basic .NET}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.