Skip to content

Instantly share code, notes, and snippets.

@nadako
Last active July 3, 2018 07:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadako/7474405 to your computer and use it in GitHub Desktop.
Save nadako/7474405 to your computer and use it in GitHub Desktop.
IntRange iterator
class IntRange
{
var index:Int;
var end:Int;
var step:Int;
inline function new(start, end, step)
{
this.index = start;
this.end = end;
this.step = step;
}
public inline function hasNext():Bool
{
return index < end;
}
public inline function next():Int
{
var old = index;
index += step;
return old;
}
public inline static function intRange(start, end, step = 1)
{
return new IntRange(start, end, step);
}
}
import IntRange.intRange;
class Sample
{
static function main()
{
for (v in intRange(0, 100, 3))
{
trace(v);
}
}
}
Sample.main = function() {
var _g_index = 0;
var _g_end = 100;
var _g_step = 3;
while(_g_index < _g_end) {
var v;
var old = _g_index;
_g_index += _g_step;
v = old;
console.log(v);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment