Presentation is loading. Please wait.

Presentation is loading. Please wait.

Doing things more than once

Similar presentations


Presentation on theme: "Doing things more than once"— Presentation transcript:

1 Doing things more than once
Loops Doing things more than once Copyright © Curt Hill

2 Repetition So far we have: What we have not done is keep things moving
Designed scenes Put actors in motion Moved the parts as they were moving What we have not done is keep things moving They move then stop What we want next is to repeat actions Copyright © Curt Hill

3 Again and Again In Computer Science we frequently use repetition
We call it: Repetition Looping Iteration Recursion Academics always like big words Alice must support iteration in the same easy way it handles everything Looping is covered in the second month in a normal class Copyright © Curt Hill

4 Loop Types Alice has two types of loops The Loop is based on a count
Do something N times The While loop is based on a condition Do something while a condition is true Both are containers like the Do Together Either of these can keep things moving forever Recall the ice skater The model continues to blink after the rest of the animation is over Copyright © Curt Hill

5 Loop Container Count based
It will execute the statements that are contained within it These are executed in order The count may be: A constant An expression, such as a parameter A math expression Infinity The Java For Copyright © Curt Hill

6 How is this used? Drag it where it is wanted
Set the number of times to loop Drag the body of the loop statements into it Next we will see three screen shots that do this: Initial drag Choosing a count When complete Copyright © Curt Hill

7 Copyright © Curt Hill

8 Copyright © Curt Hill

9 Copyright © Curt Hill

10 More on the Loop Did you notice the Show Complicated button?
The Loop can just count a fixed amount of times or it can count in other ways These items may be changed: Start count value End count value Increment Copyright © Curt Hill

11 Copyright © Curt Hill

12 Last thoughts Both repetition statements may be used anywhere
May be used in the First Method or in any you have defined They are containers like any other Any container may contain any other We could have a While in a Loop which is itself contained in another While Copyright © Curt Hill

13 Finally Use the Loop statement to keep things moving
If your actors move in straight lines then they will need to occasionally turn towards the center Copyright © Curt Hill


Download ppt "Doing things more than once"

Similar presentations


Ads by Google