Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 518

Why this recursion example in ocaml doesn't work for negative number?

$
0
0

In the Think Ocaml book the author gave this example:

let rec countdown n =     if n <= 0 then       ( print_string "Blastoff!";         print_newline())     else ( print_int n; print_newline();        countdown (n-1); ());;

The function takes an int and returns a unit. However, the code suppose to work on negative numbers as mentioned in the book but it doesn't.The logic of the code seems fine and nothing wrong with it. I thought I would share it with people who know Ocaml to see what is wrong here.


Viewing all articles
Browse latest Browse all 518

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>