Loops¶
The runtime ships a foreach macro that walks the items of a list or set without you touching indexes or lengths.
foreach¶
foreach works on lists and sets. Inside the body, item is bound to each element in order. The macro expands to a for loop built on get_len_fast and get.
Example¶
Iterating a set visits each member once, in no guaranteed order (same as Python):
Non-iterables¶
foreach relies on get_len_fast, which returns 0 for anything that is not a list or set — so passing an int, string, dict, or None simply iterates zero times rather than raising an error.
Back to README.