01969_PPT_ch05 - Programming Logic and Design Fifth...

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

View Full Document Right Arrow Icon
Programming Logic and Design Fifth Edition, Comprehensive Chapter 5 Looping
Background image of page 1

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

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 2 Objectives Learn about the advantages of looping Control loops with counters and sentinel values Nest loops Learn to avoid common loop mistakes
Background image of page 2
Programming Logic and Design, Fifth Edition, Comprehensive 3 Objectives (continued) Use a for loop Use posttest loops Recognize the characteristics shared by all loops Learn about common loop applications
Background image of page 3

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

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 4 Understanding the Advantages of Looping Looping makes computer programming efficient and worthwhile Write one set of instructions to operate on multiple, separate sets of data Loop : structure that repeats actions while some condition continues
Background image of page 4
Programming Logic and Design, Fifth Edition, Comprehensive 5 Understanding the Advantages of Looping (continued) Figure 5-1 The while loop
Background image of page 5

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

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 6 Controlling Loops with Counters and Sentinel Values As long as a Boolean expression remains true, while loop’s body executes Must control number of repetitions to avoid an infinite loop Repetitions controlled by Counter Sentinel value
Background image of page 6
Programming Logic and Design, Fifth Edition, Comprehensive 7 Using a Definite while Loop with a Counter Three actions make a while loop end correctly: Loop control variable is initialized Prior to entering the loop Loop control variable is tested If result is true, loop body entered Loop control variable must be altered in loop body while expression eventually evaluates to false Loop control variables altered by: Incrementing Decrementing
Background image of page 7

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

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 8 Using a Definite while Loop with a Counter (continued) Figure 5-2 A while loop that prints “Hello” four times
Background image of page 8
Programming Logic and Design, Fifth Edition, Comprehensive 9 Using a Definite while Loop with a Counter (continued) Definite loop : number of iterations predetermined Also called counted loop Counter : numeric variable used to count number of times an event occurs Loop control variable may be altered by user input Indefinite loop : loop iterates until some condition is true Number of iterations may vary
Background image of page 9

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

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 10 Using an Indefinite while Loop with a Sentinel Value Indefinite loop: loop performed a different number of times each time the program executes Three crucial steps: Starting value to control the loop must be provided Comparison must be made using the value that controls the loop Within the loop, value that controls the loop must be altered Loop control variable : any variable that determines whether the loop will continue
Background image of page 10
Programming Logic and Design, Fifth Edition, Comprehensive 11 Figure 5-3 Looping bank balance program
Background image of page 11

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

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

Page1 / 50

01969_PPT_ch05 - Programming Logic and Design Fifth...

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

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