// if/then/else is an expression (both branches must have the same type)
let sign n = if n > 0 then "positive" elif n < 0 then "negative" else "zero"
if true then printfn "unit-returning if needs no else"
// match (Module 11)
let describe n =
match n with
| 0 -> "zero"
| n when n < 0 -> "negative"
| _ -> "positive"
// Loops (imperative; prefer collection functions)
for i in 1 .. 5 do printfn "%d" i
for i in 10 .. -2 .. 0 do printf "%d " i // 10 8 6 4 2 0
for x in [ "a"; "b" ] do printfn "%s" x
let mutable i = 0
while i < 3 do
printfn "%d" i
i <- i + 1
// There's no break/continue: use recursion, Seq.takeWhile, List.tryFind, etc.
let firstNegative = [3; 1; -4; 2] |> List.tryFind (fun x -> x < 0) // Some -4