Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Recursion / Exercises

Count up

Problem

Write a recursive subroutine countup that prints the numbers from 1 up to $n, each on its own line. The trick: recurse first, then print — so the numbers come out in increasing order even though each call handles the largest number. Call countup(3).

Example

The program prints:

1
2
3

Solution

See the solution

Course navigation

Solution: Sum of digits   |   Solution: Count up