Selection Flashcards
sequence
a list of commands executed one after another, they are executed in the order in which they are placed within the program
selection
execution of one set of comments if some criterion is true, or another set if the criterion is false
repetition (loop)
a group of statements is repeated multiple times
invocation
a group of statements is invoked (by a call) at any place in the program to another program or sub- program
relational operators
make comparisons; results in ‘true’ (1) or ‘false’ (0)
logical operators
combine comparisons to make compound conditions
list of relational operators
< less than = greater than or equal to > greater than == equal to ~= not equal
logical operators
& and
| or
~ not
short-circuit
The second operand is evaluated only when the result is not fully determined by the first operand; it will “short circuit” past the second operand if the first one works
&&
means and, DOES short circuit
|
means or, DOES short circuit
if
end
form: if comparison statements end if the comparison evaluates to true, carry out statements. if the comparison evaluates to false, skip statements and continue
if
else
end
carries out an alternate set of statements (else) if the first comparison (if) evaluates to false if comparison statements else statements end
if
elseif
else
end
for more complex situations with multiple selection criteria: if comparison statements elseif comparison statements else statements end
switch/case
allows choice between multiple criteria which must be exactly true
switch variable
case option1, option1
statements if variable==option1, option2
…
case otherwise
statements executed if variable ~= any option
end
NOTE: once a true has been found, other cases are not evaluated.
try/catch
designed to trap errors try code block catch code block end if an error occurs in the try block, the program does not quit but runs the catch block instead
menu
used with switch/case structure
causes a menu box to appear on the screen with a series of predefined buttons
this means only desired actions may be selected; the otherwise function of the switch/case structure isn’t necessary
pseudo code
verbal description of planning code
a set of comments describing steps taken to solve a problem/ carry out a code
flow chart
graphical approach to planning code
oval: beginning of section of code
parallelogram: input or output; user interaction with program
diamond: decision point
rectangle: calculations
find( )
searches a matrix and identifies which elements in the matrix meet a given criteria
NOTE: find returns index numbers of the elements found; their positions, NOT their values