Part 3, Selection Flashcards
what is a Boolean comparison
a Boolean comparison compares two values and reports/returns back either true or false
name three Boolean comparisons
- is equal to
- is less than
- is greater than
what is a compound condition
a compound condition is a condition which compares two or more separate conditions
then reports back true or false depending on the outcome of those individual conditions and the type of compound condition being used
name three types of compound conditions
- and ( {condition 1} and {condition 2} )
- or ( {condition 1} or {condition 2} )
- not ( not{condition 2} )
you have used an “or” compound condition
what might you need to do in the following block of code
in this case we may need additional checks to find out which component of the compound condition was true
explain what a “mutually exclusive condition” is
a mutually exclusive condition is where only one outcome can ever be true out of a given set of events
example 3 = 3 so cannot be 3 < 3 or 3 > 3
what is “sequential selection”
sequential selection is having a list of selections one after the other
example if (x) { do y } if (x) { do y } if (x) { do y }
what is “nested selection”
nested selection is where you have a selection within a selection
example: if (x) { do y if (x) { do y } }
nested selections will not run if there there parents condition did not allow the selections code to run
in what situation would nested selection be more efficient than sequential selection
when there is a case of a mutually exclusive condition then a nested selection would be more efficient
this is because only one of the selections can be true meaning a nested selection would make no further checks but a sequential selection would check anyway wasting resources
what four reasons are “flag variables” or “flags” used for
a flag variable is a variable that can be used to check if
- an event has taken place
- a condition was met
- having an event confirmed without having to make checks again later in the code
- checking an event did take place which can no longer be checked
what two states will a flag variable have
- true
2. false
you see words such as “if”, “otherwise”, “depends”, “either”, “decide” in the specification
what do these words suggest you will need inside your program
words such as “if”, “otherwise”, “depends”, “either”, “decide” and any synonymous suggest that selection will be needed within your program
can you think of five words that suggest selection may be needed in your algorithm and program
- “if”
- “otherwise”,
- “depends”,
- “either”,
- “decide”
what is a “boundary value”
a boundary value is a value that determines when the program should behave differently
example:
if (x = 5) {
do something
}
here 5 is the boundary value
what is “boundary testing”
boundary testing involves testing any boundary values that might exist