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
Recursion Alice.
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.
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.
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.
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.
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.
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.
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.
Four Fundamental Pieces Instruction Control Structure Function Expression.
© Jalal Kawash Programming Peeking into Computer Science 1.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
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)
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
Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
ForLoopsInAlice1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009 Counted (For) Loops in Alice.
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.
February 25,  The BDE(Begin-During-End) event.  Worksheet – Exercise # 9 Instructions  2nd Period Test.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
DEFINITIONS FOR DR. HALVERSON’S CLASSES. DEFINING TERMS A correctly formed DEFINITION of a term consists of 2 parts  Noun – statement of the basic nature.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
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.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
Chapter 8: More on the Repetition Structure
Chapter 4 Repetition Statements (loops)
EasyCode Foundations Vocabulary Terms.
Programming: Simple Control Structures
Chapter 3: Decisions and Loops
Recursion Alice.
While: Indefinite Loops
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Recursion Alice.
Programming: Simple Control Structures
Alice in Action with Java
Doing things more than once
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
Programming: Simple Control Structures
Vocabulary Memory Cards--Sample
Topics Introduction to Repetition Structures
Programming: Simple Control Structures
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 are caught or shot down, 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 What is the problem with this solution?

Counted Loop A counted loop is an alternative way to write repetitive code Repeats instructions a counted number of times In Alice,

Code The loop instruction executes a definite number of times, specified by a count Using a loop instruction saves time is convenient

Demo

Infinity times… If “Infinity times” is selected for a loop, this means the loop will run until the program is shut down

Example To make the carousel go round continuously in an amusement park world: Built-in method

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.

Rotating each of the wheels Rotating the outer wheel 10 times Rotating the inner wheels 2 times

The entire code The two loops structures, inner wheel loop nested within the outer wheel loop. How many times does the inner loop execute?

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

Assignment Read Chapter 7- 1 Lab 7-1