Skip to content

for..in with integer bounds #537

@vtereshkov

Description

@vtereshkov

The generic for loop is very slow when simply iterating over a range of integers — see benchmarking results in #163.

Automatically analyzing the loop header for patterns like for i := 0; i < n; i++ is hard, both because it requires an infinite lookahead in the parser and because n is allowed to change during the iteration.

We could have a highly optimized for loop version similar to that used in Go since 1.22:

for i in n {   // 0 to n - 1
    foo(i)
}

or

for i in m..n {   // m to n - 1
   foo(i)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions