Last active
July 3, 2018 07:31
-
-
Save nadako/7474405 to your computer and use it in GitHub Desktop.
IntRange iterator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import IntRange.intRange; | |
| class Sample | |
| { | |
| static function main() | |
| { | |
| for (v in intRange(0, 100, 3)) | |
| { | |
| trace(v); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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