Repetition: Definite Loops Sec 53 Web Design. Objectives The Student will: Understand loops and why they are used Understand definitive loops Know how.

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.
Parameters Section 8-8 Web Design. Objectives The student will: Understand what a parameter is Understand how to use a parameter in Alice Understand how.
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.
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.
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.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 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.
Simple Python Loops Sec 9-7 Web Design.
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.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
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: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
CPS120 Introduction to Computer Science Iteration (Looping)
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
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.
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:
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Parameters Section 8-8 Web Design.
Functions Sec 51 Web Design.
EasyCode Foundations Vocabulary Terms.
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
Functions Sec 8-11 Web Design.
Control Structures
Recursion Alice.
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Simple Control Structures
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
Counted (For) Loops in Alice
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Simple Control Structures
Repetition: Definite Loops
Computer Science Core Concepts
Programming: Simple Control Structures
Vocabulary Memory Cards--Sample
Introduction to Repetition
Introduction to Repetition
Programming: Simple Control Structures
Presentation transcript:

Repetition: Definite Loops Sec 53 Web Design

Objectives The Student will: Understand loops and why they are used Understand definitive loops Know how to add loops to an Alice Program

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

Summary Definitive Loops are used to repeat something a certain number of times. Use the Loop control structure add loops to Alice code. Loops can be nested Loops can depend on function calls to set the number of times the code will be executed.

Assignment Read Chapter 7-1 Loops Download Chapter 7 sec 1 questions Do one of the two the chapter 7-1 exercises Complete the questions