ITERATIVE STRUCTURES Flashcards
this allows you to efficiently use variables
repetition
general form of the while statement
while(expression)
statement
TRUE OR FALSE: while is not a reserved word
false
this acts as a decision maker and is usually a logical expression
expression
this is called the body of the loop
statement
continues to execute endlessly
infinite loop
infinite loops are avoided by this way
including statements in loop body that assure exit condition is eventually false
if you know exactly how many pieces of data need to be read, the while loop becomes a ____________
counter-controlled loop
in sentinel-controlled while loops, ________ is tested in the condition, and the loop ends when _______ is encountered
the sentinel variable, sentinel
a flag-controlled while loop uses a _____ variable to control the loop
bool
general form of a for loop
for(initial statement; loop condition; update statement)
statement
these are called for loop control statements
initial statement, loop condition, update statement
this usually initializes a variable (called the for loop control, or for indexed, variable)
initial statement
TRUE OR FALSE: c++ does not allow you to use fractional values for loop control variables of the double type
false
general form of a do while loop
do
statement
while(expression);
in a do while loop, the _________ executes first, and then the _________ is evaluated
statement, expression
in a do while loop, it always iterates _________
at least once
if you know or can determine in advance the number of repetitions needed, this loop is the correct choice
for loop
if you do not know and cannot determine in advance the number of repetitions needed, and it could be zero, use this loop
while loop
if you do not know and cannot determine in advance the number of repetitions needed, and it is at least once, use this loop
do while loop
these alter the flow of control in loops
break and continue
this is used for 2 purposes:
- to exit early from a loop (can eliminate the use of certain (flag) variables)
- to skip the remainder of a switch structure
break statement
after the break statement executes, the program …?
continues with the first statement after the structure
this is used in while, for, and do while loops
continue
when executed in a loop, this skips remaining statements and proceeds with the next iteration of the loop
continue
this is a piece of code written on top of an existing piece of code; intended to fix a bug in the original code
software patch
TRUE OR FALSE: loops are harder to debug than sequence and selection structures
true
set of statements that remains true each time the loop body is executed
use loop invariant
this is the most common error associated with loops
off-by-one