Branching Part 2 Flashcards
Logical AND (2)
How to get to true and how to get to false
- ALl expression must evaluate to true before the entire expression is true
- If any expression is false then whole expression evaluates to false
Logical OR (2)
How to get to true and how to get to false
- If any Boolean expresion evaluates to true then the entire expression evaluates to true
- All Boolean expressions must evaluate to false before the entire expression is false
Logical NOT
may be expression by
- May be replaced by the use of an inequality operator
Nested Branches (3)
How it works+ex for type+ex content
- An IF-branch that is inside of another IF-branch
- Only when users specifies the residence as ALberta does the program ask for which city
- The nested branch is only checked if the first branch’s Boolean expression evaluates to true
Nested Desicion Making (2)
The format and how to get inner desicion to be executed?
- One desicion is made inside another
- Outer desicions must evaluate to true before inner desicions are even considered for evaluation
Why should you not use editor with diff font sizes?
Extra info will introduce syntax errors
Desicion Making with multiple IFS (2)
Later questions+ employed when…
- Later questions (IF) always asked regardless of previous questions.
- Employed when a series of independent questions will be asked
When to use multiple “Ifs”? (3)
The condition+ question and ans relationship+Boolean expression
-non-exclusive conditions (multiple conditions or options can be true/ not excclusive)
The questions are independent and the ans does not affect the next question
- More than one Boolean expressions for each if can be true
Why to not use multiple IFs (3)
ineffiecient because later Boolean expressions may be evaluated needlessly
- specifying a sequence of independent conditions can be less optimal when at most only 1 condition can be true
- For ex use If-Elise-Else as if one of the earlier “if/elise” are true the trest arent evaluated.
Multiple If-Elif-Else (2)
How it works/what if false?+Ex
- One condition evaluating to true excludes other conditions from being true (The ifs that come later are only evaluated if the earlier “ifs” evaluated to false)
- Example, having current location as calgary excludes the possibility of the current location as Edmonton, Toronto, Medicine Hat
When is nesting needed?
When you have a dealbreaker. The outer Boolean expression (gatekeeper) must be true before the inner expression will be evaluated.
When to use nested IF vs IF-AND?
When you want one consition to evaluate to true and do something even if second is False.
We dont execute Boolean body of an IF unless
expression evaluates to true
IF-Else
Checks conditions and executes one body of code if the condition is true and aother is the condition is false
Descision making with multiple IFs, the later questions are
Non exclusive conditions
always asked regardless of previous questions