Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:

Slides:



Advertisements
Similar presentations
AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
Advertisements

As you come in…  Sign in (in back) and pick up  Badge  Name Card – write your first name LARGELY on back  Any questions? (of any kind)  Put on index.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Repetition Structures
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Fall 2009ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
While: Indefinite Loops Sec 8-14 Web Design. Objectives The student will: Understand what an Indefinite Loop is Understand how create an indefinite loop.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Introducing While loops (and random numbers too) Alice.
Repeating Actions While and For Loops
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
REPETITION (loops or iteration) Schneider: Sec. 6.1 & 6.3.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Recursion Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we know is that repetition.
More About Recursion Alice. A second form of recursion A second form of recursion is used when the solution to a problem depends on the ability to break.
Copyright 2011 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Implementation Algorithm  Code World.my first method Control blocks Statements (methods,
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
CPS120 Introduction to Computer Science Iteration (Looping)
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Variables and Inheritance A More Complex Example Alice.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
Repetition Structures Chapter 5 Part The While Instruction  Combines Loop and the condition that is also used in If/else statements  The loop.
Programming: Simple Control Structures
ForLoopsInAlice1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009 Counted (For) Loops in Alice.
Obj: Programming: Simple Control Structures HW: Read section 3 – 2 AC3 D2 Do Now: 1.Log on to Alice. Open the file firstEncounter.a2w located in the folder.
CS320n –Visual Programming Definite / Counted Loops (Slides 7-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Repetition: Definite Loops Sec 53 Web Design. Objectives The Student will: Understand loops and why they are used Understand definitive loops Know how.
Programming: Simple Control Structures Sec 46 Web Design.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Tips & Techniques 4 Visible and Invisible Objects
Programming: Simple Control Structures
Chapter 3: Decisions and Loops
Programming: Simple Control Structures
Recursion Alice.
While: Indefinite Loops
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Recursion Alice.
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Simple Control Structures
Iteration: Beyond the Basic PERFORM
Design and Implementation
Counted (For) Loops in Alice
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
More About Recursion Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Tips & Techniques 4 Visible and Invisible Objects
Programming: Simple Control Structures
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Variables and Inheritance A More Complex Example
Presentation transcript:

Repetition: Definite Loops Alice

Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example: Gallery games where targets appear randomly on screen and then disappear only to appear elsewhere in the scene. Of course, actions are made to happen again and again by running an animation instruction (or a method) more than once

Example A bunny sneaks into a garden and wants to eat the broccoli. The bunny will need to hop several times to get to the broccoli.

bunny.hop

One solution Creating the same instruction again and again is somewhat tedious and the code gets longer and longer.

Counted Loop A counted loop is an alternate way to write repetitive code Repeats instructions a counted number of times

Demo Ch07Lec1BunnyHop Concepts illustrated in this example The loop instruction executes a definite number of times, specified by a count Using a loop instruction saves time is convenient

Demo Ch07Lec1Carouselinfinity Concept illustrated in this example If “Infinity times” is selected for a loop, this means the loop will run until the program is shut down

More complicated loops It is also possible to place a loop statement within another loop statement This is called nested loops

An example of nested loops The whole Ferris wheel will rotate clockwise, while the two inner wheels will rotate counterclockwise. The inner wheels should perform 2 revolutions for each outer loop revolution.

Demo Ch07Lec1FerrisWheel Concept illustrated in this example The inner loop runs completely each time the outer loop runs once. An outer loop that executes 2 times and an inner loop that executes 5 times will actually execute the inner loop 10 times.

Using a function A loop count can be computed by calling a function that returns a number value. The loop instruction automatically rounds the returned value to the nearest whole number. Demo: Ch07Lec1LoopWithFunctionCall

Assignment Read Chapter 7 Section 1, Loops

Lab Chapter 7 Lecture 1 Lab