CMP Ch.5 - Answers to Review Questions Chapter 5 1 By...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Answers to Review Questions Chapter 5 1. By indenting the statements, you make them stand out from the surrounding code. This helps you to identify at a glance the statements that are conditionally executed by a loop. 2. A pretest loop tests its condition before each iteration. A posttest loop tests its condition after each iteration. A posttest loop will always execute at least once. 3. Because they are only executed when a condition is true. 4. The while loop is a pretest loop and the do - while loop is a posttest loop. 5. The while loop. 6. The do - while loop. 7. The for loop. 8. A counter variable is used to control or keep track of the number of times a loop iterates. In a loop, the counter is usually incremented or decremented. If the counter variable is not properly initialized, it will not hold the correct number. 9. An accumulator is used to keep a running total of numbers. In a loop, a value is usually added to the current value of the accumulator. If it is not properly initialized, it will not contain the correct total.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/03/2010 for the course CMPSC 121 taught by Professor Crawford,georgew during the Spring '07 term at Penn State.

Page1 / 3

CMP Ch.5 - Answers to Review Questions Chapter 5 1 By...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online