When you want to split the flow of code into multiple cases base on some conditions. You could use if clause:
if <condition>
<action if condition is satisfied>
else
<action if condition is not satisfied>
Both actions could be single command or block
For example, you write a simple program that test if user input even number:
@echo ‘Please enter a even integer:’
@read $number_input // read user input into $number_input
if $number_input%2 =0
@echo This is an even number
@echo Congratulation
else
@echo This is not an even number
When user run the program and enter 1
> Please enter a even integer:
< 1
> This is not an even number
When user run the program and enter 2
> Please enter a even integer:
< 2
> This is an even number
> Congratulation
Multiple if else:
Used when there are multiple cases.
Ex: there are 3 students in class with corresponding student code. Write a program let user input a number, then output their name: 1 (John), 2 (Annie), 3 (Sabrina).
@echo “Enter student code 1, 2 or 3”
@read $entered_student_code
if $entered_student_code = 1
@echo John
elif $entered_student_code = 2
echo Annie
elif $entered_student_code = 3
echo Sabrina
else
echo Wrong number.