learning F#, it seems pretty cool, favourite functional language so far.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

guessing.fsx 475B

123456789101112131415161718
  1. open System
  2. let r = Random()
  3. let secretNum = r.Next(1, 100)
  4. printfn "Secret Num is between 1-100"
  5. let mutable found = false
  6. while (not found) do
  7. printfn "Enter a guess:"
  8. let guess_s = Console.ReadLine()
  9. let guess = Convert.ToInt32(guess_s)
  10. match guess with
  11. | guess when secretNum = guess ->
  12. printfn "You guessed correctly!"
  13. found <- true
  14. | guess when guess > secretNum ->
  15. printfn "Lower"
  16. | _ ->
  17. printfn "Higher"