Learn IO with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
1
Io Counter and Theme Toggle
count := 0
isDark := false
updateUI := method(
write("Counter: " .. count .. "\n")
write("Theme: " .. (if(isDark, "Dark", "Light")) .. "\n")
)
increment := method(
count = count + 1
updateUI()
)
decrement := method(
count = count - 1
updateUI()
)
reset := method(
count = 0
updateUI()
)
toggleTheme := method(
isDark = !isDark
updateUI()
)
# Simulate actions
updateUI()
increment()
increment()
toggleTheme()
decrement()
reset()
Demonstrates a simple counter with theme toggling using Io objects and message passing.
2
Io Fibonacci Sequence
a := 0
b := 1
write(a .. "\n")
write(b .. "\n")
for(i, 1, 8, do(
c := a + b
write(c .. "\n")
a := b
b := c
))
Generates the first 10 Fibonacci numbers.
3
Io Factorial Calculator
fact := method(n, if(n <= 0, 1, n * fact(n-1)))
write(fact(5) .. "\n")
Calculates factorial of a number recursively.
4
Io Prime Checker
isPrime := method(n, do(
if(n <= 1, return(false))
for(i, 2, n-1, if(n % i == 0, return(false)))
return(true)
))
write(if(isPrime(13), "Prime\n", "Not Prime\n"))
Checks if a number is prime.
5
Io Sum of List
lst := list(1,2,3,4,5)
sum := 0
foreach(x, lst, sum = sum + x)
write(sum .. "\n")
Calculates sum of a list of numbers.
7
Io Multiplication Table
n := 5
for(i, 1, 10, write(n .. " x " .. i .. " = " .. (n*i) .. "\n"))
Prints multiplication table of a number.
8
Io Celsius to Fahrenheit
c := 25
f := (c * 9 / 5) + 32
write(f .. "\n")
Converts Celsius to Fahrenheit.
9
Io Simple Alarm Simulation
temp := 80
thresh := 75
write(if(temp > thresh, "Alarm: Temperature Too High!", "Temperature Normal") .. "\n")
Simulates an alarm if a threshold is exceeded.
10
Io Random Walk Simulation
steps := 10
pos := 0
for(i,1,steps, do(
if(rand() < 0.5, pos = pos + 1, pos = pos - 1)
write(pos .. "\n")
))
Simulates a 1D random walk.