10
Programming: Simple Control Structures Part 2 – Repetition Alice

Programming: Simple Control Structures Part 2 – Repetition Alice

Embed Size (px)

Citation preview

Page 1: Programming: Simple Control Structures Part 2 – Repetition Alice

Programming: Simple Control Structures

Part 2 – Repetition

Alice

Page 2: Programming: Simple Control Structures Part 2 – Repetition Alice

More complex code

Up to now, our programs have used simple instructions for motion.

More realistic motion requires more complex program code.

Page 3: Programming: Simple Control Structures Part 2 – Repetition Alice

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

Page 4: Programming: Simple Control Structures Part 2 – Repetition Alice

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

Page 5: Programming: Simple Control Structures Part 2 – Repetition Alice

Demo

Demonstrate program development

Page 6: Programming: Simple Control Structures Part 2 – Repetition Alice

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?

Page 7: Programming: Simple Control Structures Part 2 – Repetition Alice

Possible solutions

Use the clipboard to copy and paste the code again and again – sounds a bit tedious!

Use a repetition control stucture.

Page 8: Programming: Simple Control Structures Part 2 – Repetition Alice

Loop

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

Page 9: Programming: Simple Control Structures Part 2 – Repetition Alice
Page 10: Programming: Simple Control Structures Part 2 – Repetition Alice

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)