The branch statement in Haskell is quite simple and similar to most other languages. The syntax is:
if <expression> then
else if <expression> then
main :: IO () main = do let v = 10 if v `rem` 2 == 0 then putStrLn "Even number" else putStrLn "Odd number"
In the code above, we define the variable
v has a value of 10. Then check it
v is odd (odd nunber) or even number.
Here we use keywords
do. We will learn about this keyword later.
Also Haskell has 2 functions to check if a number is odd or even or not, that is
even. For example:
main :: IO () main = do let v = 9 if v == 0 then putStrLn "Zero is neither odd nor even" else if even v then putStrLn "Even number" else if odd v then putStrLn "Odd number" else putStrLn "Unknown"
Hope this helps!