Download presentation
Presentation is loading. Please wait.
Published byLeo Antony Horn Modified over 9 years ago
1
Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)
2
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
3
The program below has a guy walk toward a girl waving… A.Before he walks toward her B.As he walks toward her C.Once he finishes walking toward her
4
When the code is done, how far will the guy have walked? A.2 meters B.5 meters C.7 meters D.10 meters
5
A blinking neon sign
6
What does this code do? How many times does it flash… Start off with 3-D text objects at opacity 0 (invisible)
7
How many times does it flash… EatAtJoes A2 times3 times B2 times6 times C3 times2 times D3 times6 times STOP, ASK PARAPHRASE Another EXAMPLE (change the #s)
8
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
9
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?
10
Outer Loop countInner Loop countTurn parameter A45.25 B451 C54 D541 Goal: Hop in a square, 5 hops on each side
11
What does this code do? A.Makes the guy move “up close” to the girl B.Makes the guy move toward the girl, but not all the way toward her C.Makes the guy move toward the girl and then go on past her D.I don’t know 3 meters
12
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, ASK PARAPHRASE EXAMPLE
13
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
14
In the nested loops that control this code how many times should the loops run? Outer LoopInner Loop A55 B5Infinite C 5 D E: I don’t know
17
After I click on an object (say the bunny) and call goBye that object stops moving around A.True B.False C.I don’t know
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.