8.1.3 Selection (IF) Flashcards
What is selection?
Selection decides which statements or instructions are executed based on a condition e.g.
IF X > Y THEN OUTPUT X ENDIF
OUTPUT X is only executed if the condition X > Y is true.
Relational Operators
Description Pseudocode
Equal to | =
Less than | <
Greater than | >
Not equal to | <>
Less than or equal to | <=
Greater than or equal to | >=
IF … THEN … ENDIF Conditional Statement
OUTPUT “What is 12 MOD 7? ”
INPUT answer
IF answer = “5“ THEN
OUTPUT “CORRECT”
ENDIF
IF … THEN … ELSE … ENDIF Conditional Statement
OUTPUT “What is 12 MOD 7?”
INPUT answer
IF answer = “5“ THEN
OUTPUT “Correct”
ELSE
OUTPUT “Incorrect”
ENDIF
IF … THEN … ELSE IF … THEN … ELSE … ENDIF Conditional Statement
INTEGER score ← 0
STRING grade ← “”
OUTPUT “Enter Score: ”
INPUT score
IF score < 50 THEN
grade ← “Fail”
ELSE IF score < 65 THEN
grade ← “Pass”
ELSE
grade ← “Merit”
ENDIF
If Statements with Boolean Operators
IF a < b AND a < c THEN
OUTPUT “a is the smallest”
ENDIF
IF name == “John” OR name == “john” THEN
OUTPUT “Hi John”
ENDIF