ForLoopsInAlice1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009 Counted (For) Loops in Alice.

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
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.
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.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Copyright 2011 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Implementation Algorithm  Code World.my first method Control blocks Statements (methods,
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Chapter 7: Repetition 7.1 Definite loops (counted) 7.2 Conditional loops (indefinite)
Recursion1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Jan 2010 Recursion in Alice.
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.
Copyright 2009 by Pearson Education Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos: Ch.
CompSci 4 Chap 7 Sec 2 Apr 7, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
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.
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.
Concepts of Algorithmic Thinking Iterations, or Loops Once is not Enough D.A. Clements, Lecturer Information School 2/23/2016 D.A. Clements, MLIS, UW Information.
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
Lists and Iteration in Alice
EasyCode Foundations Vocabulary Terms.
Programming: Simple Control Structures
Repetition Structures Chapter 9
Chapter 3: Decisions and Loops
Programming: Simple Control Structures
While: Indefinite Loops
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Doing things more than once
Repetition: Definite Loops
Iteration: Beyond the Basic PERFORM
Counted (For) Loops in Alice
Introduction to scratch animation
Repetition: Definite Loops
Repetition: Definite Loops
Introduction to Object-Oriented Programming in Alice
CISC101 Reminders Assignment 2 due this Friday.
Vocabulary Memory Cards--Sample
Topics Introduction to Repetition Structures
The structure of programming
Thinking procedurally
Presentation transcript:

ForLoopsInAlice1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009 Counted (For) Loops in Alice

ForLoopsInAlice2 Learning Goals Introduce the concept of a counted loop –A loop that keeps a counter or index –Show how a loop leads to easier to read and shorter code –Show an infinite for loop –Show a nested loop –Show a function call inside a loop

ForLoopsInAlice3 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

ForLoopsInAlice4 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.

ForLoopsInAlice5 bunny.hop

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

ForLoopsInAlice7 Counted Loop A counted loop is an alternate to repeated code –Repeats instructions a counted number of times

ForLoopsInAlice8 Demo 07BunnyHop Concepts illustrated in this example –The loop instruction executes a definite number of times, specified by a count or index –Using a loop instruction saves time is convenient Easy to modify

ForLoopsInAlice9 Demo 07Carousel 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 –This is an infinite loop

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

ForLoopsInAlice11 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.

ForLoopsInAlice12 Demo 07FerrisWheel 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.

ForLoopsInAlice13 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: 07LoopWithFunctionCall

ForLoopsInAlice14 Challenges Copy 07BunnyHop to 07BunnyOut –So that as the bunny nears the broccoli Papa rabbit (use Hare from the Animals folder) appears at the garden gateway and taps his foot –Have the bunny turn and hop out of the garden Using a loop Copy 07BunnyHop to 07BunnySquare –And have the bunny hop in a square using a nested loop Loop 4 times –Loop 3 times »Bunny hop –Bunny turn ¼ revolution

ForLoopsInAlice15 Summary A for loop is similar to a while loop –But is useful when you need a counter or index in the loop An infinite loop never stops Loops can be nested inside of other loops You can call a function inside the test for a loop