If/Else

The basic conditional expression is if which takes two or three expressions:

  1. a condition – the expression that should evaluate to #f or not-#f

  2. a consequent – the expression that should be evaluated if the condition was “true”

  3. an optional alternative – the expression that, if supplied, should be evaluated if the condition was #f

Note

There is no else keyword.

simple-if.idio
a := #t

if a {
  printf "a is true\n"
} {
  printf "a is false\n"
}

if (not a) {
  printf "(not a) is true\n"
} {
  printf "(not a) is false\n"
}

b := 0
if b {
  printf "b is true\n"
} {
  printf "b is false\n"
}
$ idio simple-if
a is true
(not a) is false
b is true

Last built at 2024-05-21T06:11:40Z+0000 from 77077af (dev) for Idio 0.3