Upload
andrew-reeves
View
214
Download
0
Embed Size (px)
Citation preview
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.
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
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
Demo
Demonstrate program development
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?
Possible solutions
Use the clipboard to copy and paste the code again and again – sounds a bit tedious!
Use a repetition control stucture.
Loop
The Loop statement is a simple control structure that provides for repeating an instruction (or block of instructions) a counted number of times.
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)