diff --git a/program/program/print-numbers-from-1-to-n-without-using-a-loop/print-numbers-from-1-to-n-without-using-a-loop.jl b/program/program/print-numbers-from-1-to-n-without-using-a-loop/print-numbers-from-1-to-n-without-using-a-loop.jl new file mode 100644 index 000000000..292a8b6d3 --- /dev/null +++ b/program/program/print-numbers-from-1-to-n-without-using-a-loop/print-numbers-from-1-to-n-without-using-a-loop.jl @@ -0,0 +1,16 @@ +function print_numbers_recursive(current, n) + if n<1 + println(-1) + return + end + + if current > n + return + end + println(current) + print_numbers_recursive(current + 1, n) +end + +# passing parameters to the recursive function +n = 10 +print_numbers_recursive(1, n)