Logic And Loops

View Code

Basic Logic

Boolean
a variable type intended to hold a value of true or false
TRUE
a value of something being valid, often represented with a non-zero number
FALSE
a value of something not being valid, often represented with zero
AND
a logical "and" statement that is true only when both sides are true
OR
logical "or" statement that is true when either side is true
XOR
logical "exclusive or" statement that is true only when one side is true
NOT
logical "not" statement that makes a true into false, false into true, AND into OR, and OR into AND
Truth Table
a diagram used to represent the total possibilities of a logical expression

If's and Switches

if
a block of coding following the if statement is run when the condition is true
else
paired with an if statement, a block of coding is run when condition is false
else if
a chaining technique of else and if statements for selective cases
select/switch
a statement for program flow; it receives a value then runs through the possible case statement under it, if the value equals a case then the lines of code after the case are executed
case
one situation for the select statement, if the value given is the same as the case then the following lines are executed
default
these lines of code are executed if no case is matched for the value passed into the switch

Loops

Definite Loop
a loop with a specific number of iterations e.g. for
Indefinite Loop
a loop with an unknown number of iterations e.g. do/while, while
Iteration
one execution of the block of code for a loop
do/while
a loop executed at least once and then when the Boolean value is TRUE
while
a loop executed when Boolean value is TRUE
until
sometimes a language will have loops expressed with until; they work just the same but now the loop stops when the Boolean value is TRUE
for
a loop executed during a counting of a variable; the loop is given a starting value, ending value, and amount to increment or de-increment often "i" is the variable

"Jumping"

break
a statement that breaks flow of program out of one block (i.e. brace couple) of code in a if/else, switch statement
continue
a statement brings the flow of program back to the condition check in the block

Prev -- Back to Portal -- Next