Loops/Downward for: Difference between revisions

(added langur language example)
Line 871:
main :: IO ()
main = forM_ [10,9 .. 0] print</lang>
 
=={{header|Haxe}}==
 
Haxe lacks a downward for-loop, but it is easy to create an iterator to serve that purpose.
 
<lang haxe>class Step {
var end:Int;
var step:Int;
var index:Int;
 
public inline function new(start:Int, end:Int, step:Int) {
this.index = start;
this.end = end;
this.step = step;
}
 
public inline function hasNext() return step > 0 ? end >= index : index >= end;
public inline function next() return (index += step) - step;
}
 
class Test {
static function main() {
for (i in new Step(10, 0, -1)) {
Sys.print('$i ');
}
}
}</lang>
 
{{out}}
<pre>10 9 8 7 6 5 4 3 2 1 0</pre>
 
=={{header|hexiscript}}==
Anonymous user