Page 102 - Code Craft Computer-7
P. 102
’
computer to make a decision. The result of the computer s decision for a condition will always be
either a true or a false.
if-then-else
The program executes the statements written after if when the condition is true. If it is false, the
statements written after 'else' will be executed.
Yes If (Condition) No
Then to be checked Else
Do this Do that
Look at these examples:
Example 1: Example 2:
If Read marks
It is Maths class If marks is > 50
Then Display Pass
Take out Maths book & notebook Else
Display Fail
Example 3: Example 4:
IF If
It is raining Number is divisible by 2
Then Then
Carry an umbrella Print "The number is EVEN"
Else Else
Do not carry an umbrella Print "The number is ODD
Try It Out #Critical Thinking
‘If’ an event occurs, 'then' what happens? Complete the sentences.
1. If the fire alarm rings then ___________________.
2. If the referee blows the whistle then ___________________.
3. If the traffic light is red then ___________________.
4. If I am sick then ___________________.
5. If a cell phone battery charge is 0 then ___________________
else ___________________.
6. If the CAPS LOCK key is ON then ___________________
else ___________________.
102

