Home   Manual   Type Index   Symbol Index   Topics Index

std::loop

a simple loop

Parameters

body

the statement sequence to execute for each iteration of the loop

return (optional; default value: pass)

Description

The loop construct replaces loops like while, do_while and forever.

To start the next iteration of the loop a tail call to the next-function has to be performed.

See also

std::from_to   a loop iterating over a sequence of values
std::next   the "keyword" (function) to start the next iteration of a loop
std::break   the "keyword" (function) to exit from a loop

Topics

Loops

Example

$i 1
loop: # "while"
  if i <= 3:
    $j 1
    loop: # "do_while"
      writeln! i "" j " = " ij
      inc &j
      if j <= 2 next
    inc &i
    next

Output

11 = 1
12 = 2
21 = 2
22 = 4
31 = 3
32 = 6

Example

$sum 0
$i 0
loop
  :
    inc &i
    plus &sum i
    if
      i < 5
      next
      break
  -> !sum

Output

sum = 15