iyi

Playground · Flow control · 13 of 33

conditions

Conditions: if, elsif, else, unless, and if as a value.

samples/tour/conditions.iyi · conditions.wasm · 121 KB
# Conditions: `if`, `elsif`, `else`, `unless`, and `if` as a value.

temperature = 23

if temperature > 30
  puts "hot"
elsif temperature > 20
  puts "warm"
else
  puts "cold"
end

# `unless` is `if not`.
unless temperature < 0
  puts "above freezing"
end

# A one-line form goes after the statement.
puts "nice day" if temperature == 23

# `if` is an expression, so it can be assigned.
label = if temperature > 20
          "warm"
        else
          "cool"
        end
puts label

# The short form: condition ? when true : when false.
puts temperature.even? ? "even" : "odd"

# `&&`, `||`, `!` combine conditions.
puts temperature > 20 && temperature < 30
puts !(temperature > 20)
output
Press Run.

recorded with iyi 0.18.0 (built on Crystal 1.22.0-dev [2a9653052] (2026-10-18)) · Linux 7.0.0-38-generic x86_64, QEMU Virtual CPU version 2.5+ · 2026-10-19

You can type in the pane: nothing here compiles, so what you type cannot run, and the page says which bytes it is running the moment the text stops being the recorded file. There is no standard input, no filesystem and no threads on this target, and one sample fails on purpose for exactly that reason.

Run executes conditions.wasm, the module the compiler built from this file, in your browser. How this works

Try it on your machine

Copy the program into conditions.iyi, change something, and run it. Only a compiler on your own machine can run what you wrote.

sh, after installing
$ iyi run conditions.iyi