Loops/N plus one half: Difference between revisions

m
prod
m (prod)
(7 intermediate revisions by 6 users not shown)
Line 380:
=={{header|Amazing Hopper}}==
Six ways to do this task in Hopper flavour "Jambo":
<syntaxhighlight lang="bennuGDc">
#include <jambo.h>
 
Line 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,683 ⟶ 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,627 ⟶ 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,559 ⟶ 3,654:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">
for (i in 1..10) {
System.write(i)
3,043

edits