📅  最后修改于: 2021-01-01 04:41:14             🧑  作者: Mango
F#if-then-else表达式测试条件。如果条件为true,则执行block ,否则执行block。
if boolean-expression then
expression1
else
expression2
let num = 11
if (num%2=0) then
printfn "It is even number"
else printfn "It is odd number"
输出:
It is odd number
在此示例中,我们使用Console.ReadLine()方法从用户那里获取输入。它返回字符串。对于数值,您必须使用Parse.Int32方法将其转换为int。
open System // Here, Importing System namespace
Console.Write("Enter a number : ")
let input = Console.ReadLine()
let num = input |> Int32.Parse // Casting input to integer
if(num%2=0) then
printfn "It is even number"
else
printfn "It is odd number"
输出:
Enter a number : 45
It is odd number