chapter 7: repetition 7.1 definite loops (counted) 7.2 conditional loops (indefinite)
TRANSCRIPT
Why is “Loop” also called “Counted Loop”
A. The loop makes things happen an indefinite number of times dependent on object positioning
B. The loop makes things happen exactly 10 times
C. The loop makes things happen a definite number of times
The program below has a guy walk toward a girl waving…
A. Before he walks toward herB. As he walks toward herC. Once he finishes walking toward her
When the code is done, how far will the guy have walked?
A. 2 metersB. 5 metersC. 7 metersD. 10 meters
What does this code do? How many times does it flash…
Start off with 3-D text objects at opacity 0
(invisible)
How many times does it flash…EatAt Joes
A 2 times 3 timesB 2 times 6 timesC 3 times 2 timesD 3 times 6 times
STOP, ASKPARAPHRASE
AnotherEXAMPLE
(change the #s)
How can I mess around with this code?
• Make EatAt flash and disappear, before Joes flashes 3 times.
• Make EatAt appear at the same time as Joes flashes 3 times
• Make Joes come on first, and EatAt flash several times while Joes is on…
• Change the number of times each flashes…• Add a third 3-D text saying “Crab Shack” and have that
flash 5 times for each time EatAt flashes 1 time• Add a third 3-D text saying “Crab Shack” and have that
flash 5 times for each time Joes flashes 1 time
Bunny Square Dance
• We want to direct the bunny to hop in a square pattern. The “length” of each side of his square should be 5 hops.
• Here’s the structure of our code, what numbers would you put in for each missing number?
Outer Loop count Inner Loop count Turn parameterA 4 5 .25B 4 5 1C 5 4 .25D 5 4 1
Goal: Hop in a square, 5 hops on each side
What does this code do?A. Makes the guy move “up close” to the girlB. Makes the guy move toward the girl, but not all the way
toward herC. Makes the guy move toward the girl and then go on past herD. I don’t know
3 meters
The primary benefit of using a function to control the number of times a loop runs is…
A. The function can be used to make the loop run a fixed number of times
B. The state of the world can be used to calculate how many times a loop should run
C. The function can be used to allow the loop to run forever.
D. I don’t know
STOP, ASKPARAPHRASE
EXAMPLE
Games: Infinite loops and events
• Set up:– A bunny, a cat, and a hawk all “continuously move” in
“squares” 2.5 meters on a side • moving forward .5 meters at a time
– An anvil hovers above their head• Game:– When I click on an animal, the anvil drops down and
“smooshes” them (they go invisible) then the anvil returns to it’s place so I can click again
– An infinite loop is used to keep all the animals continuing to move in their square patterns
In the nested loops that control this code how many times should the loops run?
Outer Loop Inner Loop
A 5 5
B 5 Infinite
C Infinite 5
D Infinite Infinite
E: I don’t know