Describe the selection structure
Boolean expressions can only be true or false (yes or no / 1 or 0) - used in every selection
structure
Dual-alternative (binary) selection structure- action for each possible outcome-
true/false (if-then-else)
Single-alternative (unary) selection structure- actions for only one outcome (if-then) -
otherwise null
if then clause- holds action executed when condition in decision is true
else clause- executes only when tested condition in decision is false
List the relational comparison operators
Relational comparison operators
Two values compared could be variables or constants
Variables have to be the same data type
= > < >= <= <>
equal greater less than greater or less or not equal
(==) than equal equal (! =)
Restrict use of "if without else" - only take action when comparison is false (best to use
positive (true) outcome)
Sometimes code is clearest in negative "if without an else"
if customerZipCode <> LOCAL_ZIP_CODE then
total = total + deliveryCharge
endif
Trivial expression (currentTotal = previousTotal)
Will always evaluate to the same result, never use
Example: true for 20 = 20 / false for 30 = 40
Common mistakes when using relational operators
missing boundary for selection, double check – saying over 65, is it >65 or >= 65?
Use AND logic
Compound condition - ask multiple questions before outcome is determined
AND decision
Requires that both of the two tests evaluate to true
Requires a nested if or a cascading if statement
Nesting AND decision for efficiency
With nesting decisions, either selection can come first
Performance time can be improved by asking questions in the right order