Loops/Continue: Difference between revisions

m
whitespace
(Pari/GP)
m (whitespace)
Line 23:
 
=={{header|Aikido}}==
<lang aikido>foreach i 1..10 {
foreach i 1..10 {
print (i)
if ((i % 5) == 0) {
Line 31 ⟶ 30:
}
print (", ")
}</lang>
}
 
</lang>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}
 
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
 
{{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:
<lang algol68>FOR i FROM 1 TO 10 DO
Line 66 ⟶ 60:
 
=={{header|AWK}}==
 
<lang awk>BEGIN {
for(i=1; i <= 10; i++) {
Line 112 ⟶ 105:
=={{header|C sharp|C#}}==
{{trans|Java}}
 
<lang csharp>using System;
 
Line 132 ⟶ 124:
=={{header|Clojure}}==
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
(doseq
[n (range 1 11)]
(do
(print n)
(if (= (rem n 5) 0) (print "\n") (print ", "))))</lang>
</lang>
 
=={{header|ColdFusion}}==
Line 156 ⟶ 146:
 
=={{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.
<lang lisp>(do ((i 1 (1+ i))) ((> i 10))
Line 176 ⟶ 165:
 
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.
 
 
<lang lisp>(loop for i from 1 to 10
Line 228 ⟶ 216:
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
 
<lang fortran>do i = 1, 10
write(*, '(I0)', advance='no') i
Line 266 ⟶ 253:
ENDDO </lang>
 
== {{header|Icon and Unicon }}==
The Icon and Unicon reserved word for 'continue' is 'next'.
 
==={{header|Icon}}===
The following code demonstrates the use of 'next':
==={{headerworks with|Unicon}}===
<lang Icon>procedure main()
every writes(x := 1 to 10) do {
Line 280 ⟶ 268:
end</lang>
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>
</lang>
==={{header|Unicon}}===
The Icon solution works in Unicon.
 
=={{header|J}}==
J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way:
 
<lang j>_2}."1'lq<, >'8!:2>:i.2 5</lang>
 
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).
Line 337 ⟶ 322:
(i % 5 = 0).if { '\n'.print; } else { ','.print; };
};</lang>
 
=={{header|Lua}}==
<lang Lua>for i = 1, 10 do
Line 372 ⟶ 358:
 
=={{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.
 
Line 458 ⟶ 443:
 
=={{header|PARI/GP}}==
<lang parigp>for(n=1,10,
print1(n);
if(n%5 == 0, print();continue);
Line 476 ⟶ 461:
=={{header|Perl 6}}==
{{trans|Perl}}
 
{{works with|Rakudo Star|2010.08}}
 
<lang perl6>for 1 .. 10 {
.print;
Line 524 ⟶ 507:
 
=={{header|PL/I}}==
<lang PL/I>loop:
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;</lang>
</lang>
 
=={{header|Pop11}}==
Line 577 ⟶ 558:
 
=={{header|R}}==
{{trans|C++}}
Translated from C++.
<lang R>for(i in 1:10)
{
Line 689 ⟶ 670:
 
Output:
 
<lang Suneido>1,2,3,4,5
6,7,8,9,10
ok</lang>
'''Bold text'''
 
=={{header|Tcl}}==
Line 704 ⟶ 683:
puts -nonewline ", "
}</lang>
 
 
=={{header|TI-89 BASIC}}==
 
<lang ti-89>
count()
Line 728 ⟶ 705:
=={{header|UnixPipes}}==
<lang bash>yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,</lang>
 
=={{header|UNIX Shell}}==
<lang bash>Z=1
Anonymous user