M6 Flashcards
are used when a
program needs to repeatedly process one or more
instructions until some condition is met, at which time
the loop ends.
Repetition structures, or loops
The process of performing the same task over and
over again is called iteration, and C++ provides builtin iteration functionality
Repetition control structures, or loops
C++ provides three different forms of repetition
statements:
- while structure
- for structure
- do-while structure
If the test occurs at the beginning of the loop, the
type of loop is called a
pre-test loop or entrancecontrolled loop.
If the test occurs at the end of the loop, the type of
loop is called a
post-test loop or exit-controlled-loop.
is used for repeating a statement
or series of statements as long as a given conditional
expression evaluates to true.
The for statement
condition is tested first (pre-test loop)
for and while statements
is used for repeating a statement or
series of statements as long as a given conditional
expression is evaluated to true.
while statement
Sentinel variable tested in condition; loop ends when
sentinel encountered
executes a statement or
statements then repeats the execution as long as a given
conditional expression evaluates to true.
do..while statement
Statements in the loop are executed first at least once,
and condition is tested last (post-test loop)
do..while statement
is used inside loops
continue statement
It is used to come out of the loop instantly.
break statement
the
control directly comes out of loop and the loop gets
terminated when encountered
break statement
It is used with if statement, whenever
used inside loop.
break statement