"do" expressions

"do"

The do keyword can be used to reduce indentation.
The below examples are equivalent:

main void() if true log "ok"main void() do if true log "ok"

do can go in front of if, for, for*, trusted, unless, until, with, or while.
All lines after the line with the do are treated as if they were an indented block.
This can chain to reduce many levels of indentation:

main void() do for x in (1, 2, 3)::nat[] do for y in (1, 2, 3)::nat[] do unless x == y log x, y

"do if" and "do unless"

Unlike a normal if, the condition in a do if or do unless can take an indented block.

main void() a nat[] = 2, 4, 6 do if every a, of x is-even x log "all even"

A do if or do unless can still have an else branch. If so, it goes to the right of the condition.
(This means the condition must fit on one line.)

main void() log foo 10 log foo 11 foo string(a nat) do if is-even a else "some odd number" "twice {a / 2}"

The else branch can be an indented block.

main void() log foo 10 log foo 11 foo string(a nat) do if is-even a else "some odd number" "twice {a / 2}"

Use do if and do unless when you want to emphasize a main path where all the ifs succeed.

main void() log describe 1 log describe 101 log describe 50 log describe 51 describe string(a nat) do if a > 10 else "too small" do if a < 100 else "too big" do unless is-even a else "too even" "ok"