I have the following list:
["A";"AA";"ABC";"BCD";"B";"C"]
I accidentally extract an item from a list. But the element i extract should have a size of 3, but not less than 3.
I am trying to do it like this:
let randomnum = (Random.int(List.length (list)));;
let rec code c =
if (String.length c) = 3 then c
else (code ((List.nth (list) (randomnum)))) ;;
print_string (code ( (List.nth (list) (randomnum)))) ;;
This works fine if at random a string of length 3 is selected from the list.
But the program does not end if the string is of length <3. I try to make a recursive call so that the new code continues to receive until we get one of length = 3.
I cannot understand why this does not end. The print statement does not print anything. A.
source
share