Repetition: Definite Loops

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 Logic and Design, Third Edition Comprehensive
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 Indefinite Loops (Slides 7-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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.
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.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
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.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
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:
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Programming: Simple Control Structures
Chapter 3: Decisions and Loops
Topics Introduction to Repetition Structures
Programming: Simple Control Structures
While: Indefinite Loops
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Repeating Actions.
Control Structures
Programming: Simple Control Structures
Doing things more than once
Introduction to pseudocode
Repetition: Definite Loops
Creating an Animation Program
Programming: Simple Control Structures
Iteration: Beyond the Basic PERFORM
Design and Implementation
Counted (For) Loops in Alice
Programming: Simple Control Structures
Programming: Simple Control Structures
Repetition: Definite Loops
Functions Alice.
Programming: Simple Control Structures
FLUENCY WITH INFORMATION TECNOLOGY
Topics Introduction to Repetition Structures
Functions Alice.
Programming: Simple Control Structures
Functions Alice.
Functions 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