Download presentation
Presentation is loading. Please wait.
1
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While
2
Fall 2007ACS-1805 Ron McFadyen2 Loop A definite loop is executed a specified number of times (also referred to as a counted loop) Also discussed back in Ch 3, page 63+ Text: A bunny sneaks into a garden and wants to eat the broccoli. The bunny will need to hop several times to get to the broccoli.
3
Fall 2007ACS-1805 Ron McFadyen3 Flowchart for Loop index < limit? Loop action(s) false true Loop action(s) executed as an index variable starts at some initial value is incremented by some increment before a next iteration goes up to some limit Set index to initial value Increment index
4
Fall 2007ACS-1805 Ron McFadyen4 bunny.hop
5
Fall 2007ACS-1805 Ron McFadyen5 bunny.hop vs Less code More flexible Easier to comprehend
6
Fall 2007ACS-1805 Ron McFadyen6 Infinite Loop In an animation we may want for some activity to never stop, unless the world stops playing
7
Fall 2007ACS-1805 Ron McFadyen7 Nested Loops Each time the ferris wheel makes a revolution the smaller wheels must turn too The inner loop is executed twice (in this example) for each iteration of the outer loop
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.