Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming: Simple Control Structures Part 2 – Repetition Alice.

Similar presentations


Presentation on theme: "Programming: Simple Control Structures Part 2 – Repetition Alice."— Presentation transcript:

1 Programming: Simple Control Structures Part 2 – Repetition Alice

2 More complex code Up to now, our programs have used simple instructions for motion. More realistic motion requires more complex program code.

3 Example Let's write code to make the mummy "walk" – a somewhat stilted motion like you would see in an old Hollywood horror film. The code will be more complex because we need to alternate left and right leg motions coordinate leg motions with the body moving forward

4 Storyboard Do in order Do together //move body and left leg mummy move forward 0.25 meters Do in order mummy's left leg move backward mummy's left leg move forward Do together //move body and right leg mummy move forward 0.25 meters Do in order mummy's right leg move backward mummy's right leg move forward

5 Demo Demonstrate program development

6 Need for Repetition The code developed in this example makes the mummy take 1 step forward on each leg. Suppose we want the mummy to take 20 steps forward?

7 Possible solutions Use the clipboard to copy and paste the code again and again – sounds a bit tedious! Use a repetition control stucture.

8 Loop The Loop statement is a simple control structure that provides for repeating an instruction (or block of instructions) a counted number of times.

9

10 Assignment Read Chapter 3-2, pp. 66 – 72 Simple Control Structures: Loop Read Tips & Techniques 3 Engineering Look & Feel (Texture Maps, Fog) Lab 3-2 (Part 2)


Download ppt "Programming: Simple Control Structures Part 2 – Repetition Alice."

Similar presentations


Ads by Google