Loops/N plus one half: Difference between revisions

Added Oberon-07
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Added Oberon-07)
Line 2,668:
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}}
3,026

edits