Classroom Notes: 1.2 Selection in Pseudocode
1) What is selection in computational thinking and programming?
Selection is a fundamental programming construct where an algorithm evaluates a comparison rule (condition) to produce a binary True or False result, determining which set of instructions to execute next.
2) Name the three essential components that form a conditional statement.
The three essential components of a conditional statement are:
- The Condition – The comparison expression evaluated as True or False.
- True Action Branch – The set of statements executed when the condition is True (following keywords like THEN).
- False Action Branch / Alternate Path – The set of statements executed when the condition is False (managed by ELSE or ELSEIF).
3) What are the primary pseudocode keywords used to construct selection statements, and what are their specific roles?
Primary pseudocode keywords used to construct selection statements are:
- IF → Initiates the conditional evaluation.
- THEN → Introduces the statements to execute if the test condition is True.
- ELSE → Introduces default statements to execute if all preceding conditions evaluate to False.
- ELSEIF → Evaluates a secondary test condition if preceding conditions were False.
- ENDIF → Marks the termination boundary of the selection block.
4) Why is indentation critical when authoring selection structures in pseudocode?
Indentation visually offsets (moves) subordinate action lines from the main vertical margin, making it clear which code blocks belong inside specific branches and where the conditional structure ends.
5) Define the operational behavior of the Boolean logical operators AND, OR, and NOT.
- AND → Returns True only if both evaluated conditions on either side are True.
- OR → Returns True if at least one condition on either side is True; it is False only when both conditions are False.
- NOT → Reverses the logical outcome (turns True to False, and False to True).
6) What is the default order of operator precedence for Boolean logic evaluation, and how can it be altered?
The standard precedence order is:
- 1. NOT (highest priority)
- 2. AND (moderate priority)
- 3. OR (lowest priority)
(), which force the enclosed expression to evaluate first.
7) Trace the following pseudocode segment and determine the final output produced.
START
score = 45
IF score >= 80 THEN
OUTPUT "Distinction"
ELSEIF score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Needs Improvement"
ENDIF
END
Output: "Needs Improvement"score = 45
IF score >= 80 THEN
OUTPUT "Distinction"
ELSEIF score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Needs Improvement"
ENDIF
END
Explanation: Since
score = 45, both conditions (45 >= 80 and 45 >= 50) evaluate to False, directing execution to the ELSE block.
8) Trace the logic of this algorithm for temperature = 22 and state the output.
START
IF temperature > 30 OR temperature < 15 THEN
OUTPUT "Extreme weather"
ELSE
OUTPUT "Comfortable weather"
ENDIF
END
Output: "Comfortable weather"IF temperature > 30 OR temperature < 15 THEN
OUTPUT "Extreme weather"
ELSE
OUTPUT "Comfortable weather"
ENDIF
END
Explanation: For
temperature = 22, both 22 > 30 (False) and 22 < 15 (False) are False. Since False OR False is False, the code inside the ELSE branch is executed.
9) Analyze the code below. If itemCount = 0, what message will be printed on screen?
START
IF NOT (itemCount = 0) THEN
OUTPUT "In Stock"
ELSE
OUTPUT "Out of Stock"
ENDIF
END
Output: "Out of Stock"IF NOT (itemCount = 0) THEN
OUTPUT "In Stock"
ELSE
OUTPUT "Out of Stock"
ENDIF
END
Explanation: When
itemCount = 0, the condition (itemCount = 0) is True. The NOT operator reverses True to False, so execution jumps to the ELSE branch.
10) Contrast how a decision branch is depicted in a visual flowchart versus text-based pseudocode.
- In Flowcharts: Selection is visually represented by a diamond decision shape with branching directional arrows marked "Yes/No" or "True/False".
- In Pseudocode: Selection is structured sequentially using control keywords (IF, THEN, ELSE, ENDIF) paired with indented code blocks.