Code Fragment can be executed only if a certain condition is met.
condition has a boolean type (true or false).
condition
true
false
Output:
if condition is true - execute the code inside if fragment.
if
Let's create a program that uses comparisons operators.
Determine whether person is adult (age >= 21) or child (age < 13) depending on his/her age.
Since age is greater than 21, line 5 executes.
age
line 5
Because age is not less than 13, line 9 is not executed.
line 9