loop Loop
The loop statement executes a block repeatedly until it is terminated by a
break or return.
: loop { ... }, plus async loop { ... } and
task loop { ... }.
Surface Syntax#
loop {
// ...
}
async loop {
// ...
}
task loop {
// ...
}
Notes:
async loopandtask loopare still loop statements: they do not end with;.- In Silk currently,
async loop/task loopfollow the same async-context restriction asasync { ... }/task { ... }: they are only allowed inside functions declared withasync(diagnostics,E2031).
Semantics#
- The body block executes repeatedly.
break;exits the nearest enclosing loop and continues execution at the statement immediately following the loop (flow break).continue;skips the remainder of the current iteration’s body and begins the next iteration (flow continue).return;exits the current function (flow return).
Type Checking Rules#
- The loop body is checked in a loop context so
break/continueare valid. break;outside a loop is rejected (diagnostics,E2007).continue;outside a loop is rejected (diagnostics,E2008).
Notes#
Supported forms:
loop { ... },async loop { ... }, andtask loop { ... }parse, type-check, and lower with correctbreak/continuesemantics.
Source repository · Edit this page · View Markdown