Back to Syllabus
Chapter 05AAYU Core - Verified

Build Fibonacci with a loop

Combine bindings, arithmetic, a loop, and a result check in a small complete program.

This lesson uses the verified core subset and links to a checked-in regression program. Its output is covered by the repository test harness. This does not imply support for features outside the lesson; see known limitations.

What you'll learn

✓Track two previous values
✓Compute the next value
✓Repeat a fixed number of times
✓Verify Fibonacci(20) equals 6765

A complete core-language exercise

The Fibonacci regression program computes the sequence iteratively. It keeps the two latest values in 'a' and 'b', computes their sum, shifts the pair, and repeats 20 times.

aayu
let a = 0
let b = 1
let i = 0
while i < 20
    let temp = a + b
    a = b
    b = temp
    i = i + 1
end
print(a)

Expected result: 6765. This version uses a loop and does not demonstrate recursive function calls. The separate regression example checks the result in an if/else.

Try It Yourself! 🚀

Change the loop bound to 10. The printed value should be 55. Add an if/else check for 55 and run the regression harness.