Chapter 4 Flashcards
Repetition structure
Makes computer repeat code as necessary. Includes condition-controlled loops and count-controlled loops.
while loop
while condition is true, do something. a while condition is a condition-controlled loop. A condition is tested for true or false. The loop will continue as long as the condition is true.
Iteration
One execution of the body of the loop.
Infinite loop
Loop that does not have a way of stopping.
for loop
The for loop is a count-controlled loop. The for loop iterates a specific number of times. It’s designed to work with a sequence of data items. It will iterate once for each item in the sequence.
Target variable
The variable which is the target of the assignment at the beginning of each iteration.
Iterable
Contains a sequence of values that can be iterated over.
Augmented assignment operators
Special set of operators. Examples
\+= -= *= /= %=
Sentinel
Special value that marks the end of a sequence of items.
Input validation
Inspecting input before it is being processed by the program.
Nested loop
Loop that is contained inside another loop.
Loop control variable
The variable that has its value tested in a loop (and thus controls the number of iterations).
List the five elements of a loop.
- Initialization. Set up the proper conditions for the start of the loop, including identifying a loop control variable.
- Loop test. Specify the conditions that must be satisfied for the body of the loop to be executed.
- Main work. Statements to be executed during each iteration of the loop.
- Update. The value of the loop control variable should be changed inside the body of the loop. The pattern of changes must be such that the loop eventually terminates.
- Finalization (optional). Add any final statements to properly wrap things up.
Show an operator precedence table, including relational and logical operators.
() ** * / // % \+ - < >= > <= != == not and or