classic-for

A library that enables C-style for loops within Haxe.
https://github.com/player-03/classic-for

To install, run:

haxelib install classic-for 0.3.1 

See using Haxelib in Haxelib documentation for more information.

README.md

Classic "for"

A library that enables C-style for loops within Haxe.

Usage

class Example implements ClassicFor {
    public static function add1To10():Int {
        var sum:Int = 0;
        
        @for(var i:Int = 1, i <= 10, i++) {
            sum += i;
        }
        
        return sum;
    }
}

To enable this feature in all of your classes at once, add the following command-line argument:

--macro addGlobalMetadata("com.your.package.here", "@:build(ClassicFor.build())")

In Lime/OpenFL, this would be one of the following:

<haxeflag name="--macro" value="addGlobalMetadata('com.your.package.here', '@:build(ClassicFor.build())')'" />
<haxeflag name="--macro" value="addGlobalMetadata('${APP_PACKAGE}', '@:build(ClassicFor.build())')'" />

In the former case, you have to type out your package name. The latter is more convenient, but it only works if you define your package using the <meta /> tag, not the <app /> tag.

Notes

  • Haxe does not allow semicolons between parentheses, so it is not possible to use the exact same syntax as C.
  • If you provide exactly three loop arguments, the macro will treat the loop exactly like a for loop in C. Otherwise, it will be forced to guess what the arguments mean.
  • When guessing, the macro finds the first argument that is not an assignment operation or variable declaration. This will be considered the "loop condition."
  • Everything before the condition will be considered "initialization code," and everything afterwards will be considered "increment code."
  • If no condition is found, the loop will repeat endlessly. (Or until a break statement.)
Contributors
player_03
Version
0.3.1
Published
2 years ago
License
MIT

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github