if-else statement is a flow-control statement for all programming languages. It is used for decision making during the execution of a code flow. Although the working of the
if-else statement is common to all programming languages, it has different syntax depending on the programming language used. In this shot, we will learn how to use an
if-else statement in Ocaml.
This is the syntax for writing an
if-else statement in Ocaml:
if condition then code else code
let b = 6;; let a = 7;; if a > b then print_int(a) else print_int(b);;
if-elsestatement to print
aif it is greater than
band vice versa. Notice how we follow the exact description of the syntax. After the
ifcondition, we use the
thenkeyword to wrap the code we want to execute.
View all Courses