Intermediate
Functions & Handlers
Define functions, handlers, recursion (factorial, fibonacci).
examples/functions.bubble-- Functions and handlers in Bubble -- Define a function using 'function ... end'function double(x) return x * 2end double -- Define a handler using 'on ... end'on greet name say "Hello," && name & "! Welcome to Bubble! 🫧"end greet -- Define a recursive functionfunction factorial(n) if n is less than 2 then return 1 end if return n * factorial(n - 1)end factorial -- Fibonacci functionfunction fibonacci(n) if n is less than 2 then return n end if return fibonacci(n - 1) + fibonacci(n - 2)end fibonacci -- Use the functionssay "=== Functions ==="say "double(21) =" && double(21)say "double(7) =" && double(7) say ""say "=== Handlers ==="greet("World")greet("Bubble Developer") say ""say "=== Factorial ==="repeat with i from 1 to 10 say i & "! =" && factorial(i)end repeat say ""say "=== Fibonacci ==="repeat with i from 0 to 12 say "fib(" & i & ") =" && fibonacci(i)end repeat