Step 3: A range of answers
In this case, the easiest way to see what is going on in the second part of the code is simply to run the whole thing.
Challenge
let collatz = fn(n_) {
var n = n_
var steps = 0
loop {
if n == 1 { break steps }
n := (if n % 2 == 0 { n / 2 } else { n * 3 + 1 })
steps := steps + 1
}
}
for i in range(5) {
let n = i + 2
print(collatz(n))
}
Goal
Try to make the program to display only five numbers.