classic-for 0.3.1

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

Released 2016-06-14.

To install, run:

haxelib install classic-for 0.3.1

See using Haxelib in Haxelib documentation for more information.

Current version0.3.1
StatisticsInstalled 25 times
Tags macro

Classic "for"

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


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("", "@:build(")

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

<haxeflag name="--macro" value="addGlobalMetadata('', '@:build(')'" />
<haxeflag name="--macro" value="addGlobalMetadata('${APP_PACKAGE}', '@: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.


  • 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.)