Branching/Looping Flashcards
Branch
Program path taken if an expression’s value is true
Nested if-else
If-else statement as a branch within another if-else statement
Boolean
True or False
Operator Chaining
Evaluates chain of operators left to right until false
a < b < c If a is less then b check if b is less than c
Code Block
Series of statements that are grouped together defined by indentation level
Loop
Loop statements (loop body) repeatedly executed while loop’s expression is true. Each execution is an iteration.
While Loop
Repeatedly executes while loop expression is true. At the end of the loop the expression is evaluated again.
Use when iterations not known before entering
Sentinel Value
Value when evaluated by loop expression causes the loop to terminate
Infinite Loop
Will always execute because expression is always true. Often caused by assuming equality will be reached.
Loop Variable
Counts the number of iterations
i = 1 while i <= N: loop body i = i + 1
For Loop
Performs some action during each iteration
Use when iterations known before entering loop
Use when accessing elements of a container
Break Statement
Causes an immediate exit from loop
Continue Statement
Causes immediate jump to loop header statement
Good way to add conditions to for loops
Loop Else
Else statement executes if loop terminates without using break statement