Chap5 - Chapter 5 1 Outline Basic Loop Structures while...

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

View Full Document Right Arrow Icon
1 Chapter 5
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline ± Basic Loop Structures ± while Loops ± Interactive while Loops ± for loops ± Loop Programming Techniques ± Nested Loops ± do while Loops ± Common Programming Errors
Background image of page 2
3 Basic Loop Structures ± Repetition structure has four required elements: ± Repetition statement ± Condition to be evaluated ± Initial value for the condition ± Loop termination ± Repetition statements include ± while ± for ± do while
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Basic Loop Structures (continued) ± The condition can be tested ± At the beginning: pretest or entrance- controlled loop ± At the end: posttest or exit-controlled loop ± Something in the loop body must cause the condition to change, to avoid an infinite loop, which never terminates
Background image of page 4
5 Basic Loop Structures (continued) ± Pretest loop: condition is tested first; if false, statements in the loop body are never executed ± while and for loops are pretest loops
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Basic Loop Structures (continued) ± Posttest loop: condition is tested after the loop body statements are executed; loop body always executes at least once ± do while is a posttest loop
Background image of page 6
7 Basic Loop Structures (continued) ± Fixed-count loop: loop is processed for a fixed number of repetitions ± Variable-condition loop: number of repetitions depends on the value of a variable
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 while Loops ± while statement is used to create a while loop Syntax: while (expression) statement; ± Statements following the expressions are executed as long as the expression condition remains true (evaluates to a non-zero value)
Background image of page 8
9 while Loops (continued) Figure 5.3 Anatomy of a while loop.
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 while Loops (continued)
Background image of page 10
11 while Loops (continued)
Background image of page 11

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

View Full DocumentRight Arrow Icon
Interactive
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

Chap5 - Chapter 5 1 Outline Basic Loop Structures while...

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

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