HomeManualTopicsTypesSymbols

Loops

Description

There are no loop instructions in Funky and it isn't really possible to "loop" over some code.

But there are a lot of functions that offer anonymous recursion that look and work a lot like loops.

The make use of the dynamic variables of Funky that can be redefined in inner scopes.

A "loop" consists of a body and a finally function. The finally function is called after the last "iteration" of the loop and is responsible to return any results from the "loop". Due to the fact that the "loop" is a normal function it cannot make any changes to its caller's variables directly.

All "loops" redefine the function std::next to start the next iteration of the "loop". This std::next function must be called at the end of each "iteration".

Some loops also offer a std::break function which can be used to stop "iterating" and calls the finally function immediately.

Some "loops" define the no-op function std::pass as the default function for finally.

Instead of calling std::next or std::break a loop's body can direct return one or more results.

Due to some clever context saving and restoring "loops" can be nested to any level.

The most basic "loop" is std::loop.

Practically all std::collections support std::for_each.

std::break cancels the current "loop"
std::for_each iterates over all items of a collection
std::from_to a loop iterating over a sequence of values
std::from_to_by a loop iterating over a sequence of values
std::loop a simple "loop"
std::next starts the next "iteration" of a "loop"
std::repeat invoke a statement sequence for a specific number of times
std::while a "while" loop
std::while_not a "while" loop