Selection - IF Statements
The IF.. THEN... ELSE... statement
The IF.. THEN... ELSE... statement
We use the if statement when:
- there are 3 or less different options to choose from
- we may be comparing different variables for different options
The Syntax (in psuedocode)
The Syntax (in psuedocode)
//1 branch
IF <conditional statement> THEN
<code to carry out if true>
ENDIF
//2 branches
IF <conditional statement> THEN
<code to carry out if true>
ELSE
<Code to carry out if false>
ENDIF
//3 branches - A Nested IF
IF <conditional statement> THEN
<code to carry out if true>
ELSE
IF <conditional statement> THEN
<code to carry out if true>
ELSE
<Code to carry out if false>
ENDIF
ENDIF