Tutorial by Examples: collatz

The while loop runs its body as long as the condition holds. For instance, the following code computes and prints the Collatz sequence from a given number: function collatz(n) while n ≠ 1 println(n) n = iseven(n) ? n ÷ 2 : 3n + 1 end println("1... and 4, 2, 1, ...

Page 1 of 1