01969_PPT_ch05

# 01969_PPT_ch05 - Programming Logic and Design Fifth Edition...

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

Programming Logic and Design Fifth Edition, Comprehensive Chapter 5 Looping

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

View Full Document
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
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

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

View Full Document
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
Programming Logic and Design, Fifth Edition, Comprehensive 5 Understanding the Advantages of Looping (continued) Figure 5-1 The while loop

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
Programming Logic and Design, Fifth Edition, Comprehensive 11 Figure 5-3 Looping bank balance program

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 08/18/2011 for the course COMP 230 taught by Professor Deokar during the Summer '11 term at DeVry Cincinnati.

### Page1 / 50

01969_PPT_ch05 - Programming Logic and Design Fifth Edition...

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

View Full Document
Ask a homework question - tutors are online