Loops/N plus one half: Difference between revisions

m
prod
imported>Katsumi
No edit summary
m (prod)
(10 intermediate revisions by 6 users not shown)
Line 377:
end.
</syntaxhighlight>
 
=={{header|Amazing Hopper}}==
Six ways to do this task in Hopper flavour "Jambo":
<syntaxhighlight lang="c">
#include <jambo.h>
 
Main
i=1
Loop if ' Less equal (i,10)'
Set 'i', Print if ( #(i<10), ",","")
++i
Back
Prnl
Loop for ( i=1, #(i<=10), ++i )
Set 'i', Print only if ( #(10-i), ",")
Next
Prnl
i=1
Loop
Set 'i', Print only if ( #(10-i), ",")
++i
While ' #(i<=10) '
Prnl
i=1
Loop
Set 'i', Print only if ( #(10-i), ",")
++i
Until ' #(i>10) '
Prnl
i=1
Loop
Set 'i', and print it
Break if '#( !(10-i) )'
Set '","'
++i
Back
Prnl
 
/* assembler Hopper */
i=1
loop single:
{i,10,i} sub, do{{","}}, print
++i, {i,11}, jneq(loop single)
puts("\n")
End
</syntaxhighlight>
{{out}}
<pre>
1,2,3,4,5,6,7,8,9,10
1,2,3,4,5,6,7,8,9,10
1,2,3,4,5,6,7,8,9,10
1,2,3,4,5,6,7,8,9,10
1,2,3,4,5,6,7,8,9,10
1,2,3,4,5,6,7,8,9,10
</pre>
 
=={{header|AmigaE}}==
Line 714 ⟶ 769:
PRINT
</syntaxhighlight>
 
==={{header|bootBASIC}}===
There are no for/next or do/while loops in bootBASIC. Only goto.
<syntaxhighlight lang="BASIC">
10 a=1
20 print a ;
30 if a-10 goto 100
40 goto 130
100 print ", ";
110 a=a+1
120 goto 20
130 print
</syntaxhighlight>
{{out}}
<pre>1, 2, 3, 4, 5, 6, 7, 8, 9, 10</pre>
 
==={{header|Chipmunk Basic}}===
Line 1,628 ⟶ 1,698:
Enum.to_list(1..10) |> Loops.n_plus_one_half
</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
int LAST_ITERATION = 10
for int i = 1; i <= LAST_ITERATION ; ++i
write(i)
if i == LAST_ITERATION do break end
write(", ")
end
writeLine()
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
</pre>
 
=={{header|Erlang}}==
Line 2,572 ⟶ 2,657:
{{out}}
<pre>1, 2, 3, 4, 5, 6, 7, 8, 9, 10</pre>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
for i in 1.. {
print -n $i
if $i == 10 {
print ""
break
}
print -n ", "
}
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
</pre>
 
 
=={{header|Oberon-07}}==
===Using a FOR loop===
Should also work with Oberon-2.
<syntaxhighlight lang="modula2">
MODULE LoopsNPlusOneHalf1;
IMPORT Out;
 
VAR i :INTEGER;
 
BEGIN
FOR i := 1 TO 10 DO
Out.Int( i, 0 );
IF i < 10 THEN Out.String( ", " ) END
END
END LoopsNPlusOneHalf1.
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
</pre>
 
===Using an extended WHILE loop===
Whilst probably not the best way of handling the task, this example demonstrates the extended WHILE loop available in Oberon-07.<br/>
The WHILE loop can have multiple conditions and DO pats. The conditions following WHILE and ELSIF are evaluated in order and the DO part corresponding to the first TRUE one is executed.<br/>
The loop terminates when all the conditions evaluate to FALSE
<syntaxhighlight lang="modula2">
MODULE LoopsNPlusOneHalf;
IMPORT Out;
 
VAR i :INTEGER;
 
BEGIN
i := 0;
WHILE i < 9 DO
i := i + 1;
Out.Int( i, 0 );
Out.String( ", " )
ELSIF i < 10 DO
i := i + 1;
Out.Int( i, 0 )
END
END LoopsNPlusOneHalf.
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
</pre>
 
=={{header|Objeck}}==
Line 3,504 ⟶ 3,654:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">
for (i in 1..10) {
System.write(i)
3,043

edits