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.