Top Banner
Chapter 7: Repetition • 7.1 Definite loops (counted) • 7.2 Conditional loops (indefinite)
17

Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

Dec 24, 2015

Download

Documents

Leo Antony Horn
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

Chapter 7: Repetition

• 7.1 Definite loops (counted)• 7.2 Conditional loops (indefinite)

Page 2: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 3: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 4: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

When the code is done, how far will the guy have walked?

A. 2 metersB. 5 metersC. 7 metersD. 10 meters

Page 5: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

A blinking neon sign

Page 6: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

What does this code do? How many times does it flash…

Start off with 3-D text objects at opacity 0

(invisible)

Page 7: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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)

Page 8: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 9: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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?

Page 10: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 11: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 12: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 13: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 14: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

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

Page 15: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)
Page 16: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)
Page 17: Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)

After I click on an object (say the bunny) and call goBye that object stops moving around

A. TrueB. FalseC. I don’t know