Learn REBOL with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
1
Rebol Counter and Theme Toggle
count: 0
isDark: false
updateUI: func [] [
print join "Counter: " count
print join "Theme: " (either isDark ["Dark"] ["Light"])
]
increment: func [] [
count: count + 1
updateUI
]
decrement: func [] [
count: count - 1
updateUI
]
reset: func [] [
count: 0
updateUI
]
toggleTheme: func [] [
isDark: not isDark
updateUI
]
; Simulate actions
updateUI()
increment()
increment()
toggleTheme()
decrement()
reset()
Demonstrates a simple counter with theme toggling using Rebol variables and functions.
2
Rebol Fibonacci Sequence
a: 0
b: 1
print a
print b
foreach i 1 2 3 4 5 6 7 8 [
c: a + b
print c
a: b
b: c
]
Generates first 10 Fibonacci numbers.
3
Rebol Factorial Calculator
fact: func [n][
either n = 0 [1] [n * fact n - 1]
]
print fact 5
Calculates factorial of a number.
4
Rebol Prime Checker
is-prime?: func [n][
if n < 2 [return false]
foreach i 2 to n - 1 [
if n // i = 0 [return false]
]
true
]
print either is-prime? 13 ["Prime"] ["Not Prime"]
Checks if a number is prime.
5
Rebol Sum of Block
lst: [1 2 3 4 5]
sum: 0
foreach n lst [sum: sum + n]
print sum
Calculates the sum of a block of numbers.
7
Rebol Multiplication Table
n: 5
foreach i 1 2 3 4 5 6 7 8 9 10 [
print rejoin [n " x " i " = " n * i]
]
Prints multiplication table of a number.
8
Rebol Celsius to Fahrenheit
c: 25
f: (c * 9 / 5) + 32
print f
Converts Celsius to Fahrenheit.
9
Rebol Simple Alarm Simulation
temp: 80
thresh: 75
print either temp > thresh ["Alarm: Temperature Too High!"] ["Temperature Normal"]
Simulates an alarm when temperature exceeds a threshold.
10
Rebol Random Walk Simulation
steps: 10
pos: 0
foreach i 1 2 3 4 5 6 7 8 9 10 [
if random 1 < 0.5 [pos: pos + 1] [pos: pos - 1]
print pos
]
Simulates a 1D random walk.