8.1.3 Selection (IF) Flashcards

1
Q

What is selection?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Relational Operators

A

Description Pseudocode

Equal to | =
Less than | <
Greater than | >
Not equal to | <>
Less than or equal to | <=
Greater than or equal to | >=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

IF … THEN … ENDIF Conditional Statement

A

OUTPUT “What is 12 MOD 7? ”
INPUT answer

IF answer = “5“ THEN
OUTPUT “CORRECT”
ENDIF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

IF … THEN … ELSE … ENDIF Conditional Statement

A

OUTPUT “What is 12 MOD 7?”
INPUT answer

IF answer = “5“ THEN
OUTPUT “Correct”
ELSE
OUTPUT “Incorrect”
ENDIF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

IF … THEN … ELSE IF … THEN … ELSE … ENDIF Conditional Statement

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If Statements with Boolean Operators

A

IF a < b AND a < c THEN
OUTPUT “a is the smallest”
ENDIF

IF name == “John” OR name == “john” THEN
OUTPUT “Hi John”
ENDIF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly