FizzBuzz
Generate it:
lumen --examples fizzbuzz
print 'N='
inputInt &x
repeat x, n
n = n + 1
if n % 15 == 0
println 'FizzBuzz'
elif n % 5 == 0
println 'Buzz'
elif n % 3 == 0
println 'Fizz'
else
println n
endif
endrepeat
The classic FizzBuzz, now written with modern Lumen loop and condition syntax:
repeat x, ncreates a loop that runsxtimes with an iteratornthat starts at 0 (see Loops).- Since the iterator starts at 0, we increment it to get 1-indexed counting:
n = n + 1. %(modulo) checks divisibility, usingelifchains instead of nested blocks (see Conditionals).
Note the divisibility-by-15 check runs first — this is the “check the most specific case first” trick FizzBuzz solutions need in any language, since 15 is also divisible by 3 and 5.
Scan into Android
See Lumen on Android for how the scan-and-run pipeline works.