Repetition: Definite Loops

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
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.
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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.
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.
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.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
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.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
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.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Classes, Objects, and World-level Methods
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
Repeating Actions.
Control Structures
Recursion Alice.
Programming: Simple Control Structures
Doing things more than once
Repetition: Definite Loops
Creating an Animation Program
Classes, Objects, and World-level Methods
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
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
More About Recursion Alice.
Functions Alice.
Programming: Simple Control Structures
Classes, Objects, and World-level Methods
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions 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 If you have previously covered chapter 3, consider skipping slides 1-10 and using slides 11-16 as a review before covering While loops.

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 Concepts illustrated in this example Ch07Lec1BunnyHop 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. In an animation, opposite actions that occur simultaneously effectively cancel each other out in terms of the rendered action. To demonstrate, set the outer loop to 1 time and the inner loop to 2 times. The inner wheel will look as though it rotates only once. As another example, you would see the same kind of result if you try to turn a person's head left and right ¼ revolution at the same time.

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