FizzBuzz
Generate it:
lumen --examples fizzbuzz
N = 0
print 'N='
inputInt &N
println ''
i = 1
label loop
i15 = i % 15
if i15 == 0
println 'FizzBuzz'
else
i3 = i % 3
if i3 == 0
println 'Fizz'
else
i5 = i % 5
if i5 == 0
println 'Buzz'
else
println i
endif
endif
endif
i = i + 1
if i <= N
jump loop
endif
The classic FizzBuzz, and the best single example of how the language pieces fit together:
- A
label loop/ conditionaljump looppair drives iteration fromi = 1up toN(see Labels & Jumps). %(modulo) checks divisibility by 15, then 3, then 5.- Three levels of nested
if/else/endifstand in for theelseifchain Lumen doesn’t have (see Conditionals).
Note the divisibility-by-15 check runs first — this is the same “check the most specific case first” trick FizzBuzz solutions need in any language, since 15 is also divisible by 3 and 5.