CS320n –Visual Programming Definite / Counted Loops (Slides 7-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.

Slides:



Advertisements
Similar presentations
Mike Scott University of Texas at Austin
Advertisements

AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
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.
CS320n –Visual Programming Class-level Methods and Inheritance – Part 1 Mike Scott (Slides 4-3-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Repetition Structures
Fall 2009ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
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.
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Copyright 2011 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Implementation Algorithm  Code World.my first method Control blocks Statements (methods,
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)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
CATCH SCRATCH! Programming from Scratch. Remember Scratch?
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
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)
CompSci 4 Chap 8 Sec 1 Nov 17, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Mathematical Expressions, Conditional Statements, Control Structures
CS320n – Elements of Visual Programming Lists Mike Scott (Slides 9-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Advanced Recursion (Slides 8-2) 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.
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)
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
Repetition Structures Chapter 5 Part The While Instruction  Combines Loop and the condition that is also used in If/else statements  The loop.
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.
Repetition: Definite Loops Sec 53 Web Design. Objectives The Student will: Understand loops and why they are used Understand definitive loops Know how.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Programming: Simple Control Structures Sec 46 Web Design.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
CS320n –Visual Programming Problem Solving Case Study (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CompSci 4 Chap 10 Nov 22, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
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.
CS320n – Elements of Visual Programming List Search Mike Scott (Slides 9-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
EasyCode Foundations Vocabulary Terms.
Programming: Simple Control Structures
Programming: Simple Control Structures
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Control Structures
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
CS320n –Visual Programming
Doing things more than once
CS320n –Visual Programming
Repetition: Definite Loops
Iteration: Beyond the Basic PERFORM
Counted (For) Loops in Alice
Repetition: Definite Loops
Repetition: Definite Loops
Introduction to Object-Oriented Programming in Alice
Vocabulary Memory Cards--Sample
Lesson 18 – how to add a new button for pivot right
Presentation transcript:

CS320n –Visual Programming Definite / Counted Loops (Slides 7-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.

Visual ProgrammingDefinite / Counted Loops2 What We Will Do Today Learn how what definite loops are and how to use them in a program

Visual ProgrammingDefinite / Counted Loops3 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 Actions are made to happen again and again by running an animation instruction (or a method) more than once

Visual ProgrammingDefinite / Counted Loops4 Computers are Fast This is why we use computers. The number of instructions a CPU can carry out is mind boggling –Intel Processor: 3.20 gigahertz. –CPU doing 3,200,000,000 instructions per second. –Simple instructions like adding two numbers, looking up the value of a variable Lots of simple instructions can so quickly can accomplish a lot –3D animations, working with DNA, complex simulations.

Visual ProgrammingDefinite / Counted Loops5 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.

Visual ProgrammingDefinite / Counted Loops6 bunny.hop

Visual ProgrammingDefinite / Counted Loops7 bunny.hop Makes bunny hop up and down, making a sound and traveling forward 0.8 meters Code on next slide How do we get the bunny to hop enough times to get over to the broccoli?

Visual ProgrammingDefinite / Counted Loops8 One solution Does this work? Are there any problems with it?

Visual ProgrammingDefinite / Counted Loops9 Counted Loop A counted loop is an alternative way to repetitive code Repeats instructions a counted number of times One of the commands available in Alice

Visual ProgrammingDefinite / Counted Loops10 Code for Loops The loop instruction executes a definite number of times, specified by a count. (Set when insert loop) Using a loop instruction – saves time when coding – is convenient, easy to change count –can use a function that returns a number in place of the count

Visual ProgrammingDefinite / Counted Loops11 Modify the Bunny Animation Make the bunny hop over to a broccoli and eat it Then hop to next broccoli and eat it move broccoli so not all together only do with 3 broccoli –fairly easy to expand to more broccoli

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

Visual ProgrammingDefinite / Counted Loops13 Example 1: Add a bunny Add a bunny to the broccoli scene this bunny should jump up and down while the other bunny eats all the broccoli

Visual ProgrammingDefinite / Counted Loops14 Does this Work?

Visual ProgrammingDefinite / Counted Loops15 How Do We fix This? Get both bunnies to move –one definitely (the one that eats the broccoli) –one indefinitely (the one that hops up and down until the movie stops?)

Visual ProgrammingDefinite / Counted Loops16 Example 2: Carousel To make the carousel go round continuously in an amusement park world:

Visual ProgrammingDefinite / Counted Loops17 More complicated loops What can be placed in a loop? –any number of other commands –including other loops –a loop within a loop –this is a called a nested loop Example in book: a double ferris wheel

Visual ProgrammingDefinite / Counted Loops18 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.

Visual ProgrammingDefinite / Counted Loops19 Rotating each of the wheels Rotating the outer wheel 10 times Rotating the inner wheels 2 times

Visual ProgrammingDefinite / Counted Loops20 The Complete Program The two loops structures, inner wheel loop nested within the outer wheel loop. How many times does the inner loop execute?

Visual ProgrammingDefinite / Counted Loops21 Using a Function for Count 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.