#f5f5dc;”>#Mastery22
#f5f5dc;”>Repetition structures, or loops, are used when a program needs to repeatedly process one or more instructions until some condition is met, at which time the loop ends. Many programming tasks are repetitive, having little variation from one item to the next. The process of performing the same task over and over again is called iteration, and C++ provides built-in iteration functionality. A loop executes the same section of program code over and over again, as long as a loop condition of some sort is met with each iteration. This section of code can be a single statement or a block of statements (a compound statement). (http:/
Two types of repetition structures: pretest and posttest loops
Pretest:
- Loop condition appears at beginning of pretest loop
- Determines number of times instructions w/in loop body are processed
Types of pretest loop:
- while
- for
Posttest:
- Loop condition appears at end of posttest loop
- Determines number of times instructions w/in loop body are processed
- HOWEVER, instructions processed at least once–the first time
#TC1017
EXAMPLE!!!