Stuck in an infinite loop in a function

I am stuck in an infinite loop in this function:

let rec showGoatDoorSupport(userChoice, otherGuess, aGame) =                                       
    if( (userChoice != otherGuess) && (List.nth aGame otherGuess == "goat") ) then otherGuess
    else showGoatDoorSupport(userChoice, (Random.int 3), aGame);;

And this is how I call the function:

showGoatDoorSupport(1, 2, ["goat"; "goat"; "car"]);             

In the first condition in the function, I compare the first 2 input parameters (1 and 2), if they are different, and if the item in the list by index "otherGuess" is not equal to "goat", I want to return this otherGuess.

Otherwise, I want to run the function again with a random number between 0-2 as the second input parameter.

The point is to continue trying to run this function until the second parameter is equal to the first, and this slot in the list is not a "goat", and then returns the number of this slot.

+5
source share
2 answers

==, . =. , . ( , OCaml.)

$ ocaml
        OCaml version 4.00.0

# "abc" == "abc";;
- : bool = false
# "abc" = "abc";;
- : bool = true
+8

- String.compare. :

 if String.compare str1 str2 = 0 then (* case equal *)
 else (* case not equal *)
+1

All Articles