Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.

Slides:



Advertisements
Similar presentations
AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
Advertisements

Chapter 7.2 While – Conditional Loops. What is the BEST description of how many times a while loop executes? A.Some fixed number of times that the programmer.
As you come in…  Sign in (in back) and pick up  Badge  Name Card – write your first name LARGELY on back  Log in:  Launch/Start Alice  Any questions?
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
1 Fall 2009ACS-1805 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique shown in text) Directed.
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.
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
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.
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 Functions A function is a collection of statement, similar to a method, but a function is defined to return a value to.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
Fall 2007ACS-1805 Ron McFadyen1 Functions and if-else A function is a collection of statement, similar to a method, but a function is defined to return.
Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods.
1 Fall 2008ACS-1805 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique) Text presents one of these.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 7 Repetition.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 8 Recursion.
Fall 2008ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
Fall 2009ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
Fall 2007ACS-1805 Ron McFadyen1 Ch 9 Lists In some animations, several objects must perform the same actions Example: A marching band, where the band members.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Lecture 11 Alice Project Deliverable 1: Extension to Midnight! Midterm next class – Midterm review 4-6pm WED Pepper Canyon Hall 106 – Red scantron (1/2.
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
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.
CompSci 4 Chap 7 Sec 2 Apr 7, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Alice Programming Step 1:Design Copyright 2011 Wanda Dann, Don Slater, Steve Cooper.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
1 Fall 2007ACS-1903 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique) Text presents one of these.
Mathematical Expressions, Conditional Statements, Control Structures
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Fall 2009ACS-1805 Ron McFadyen1 Chapter 2 Program Design & Implementation.
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.
Programming: Simple Control Structures
Fall 2007ACS-1805 Ron McFadyen1 Chapter 2 Creating Your First Animation (An Introduction to Programming)
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.
Programming: Simple Control Structures Sec 46 Web Design.
Fall 2008ACS-1805 Ron McFadyen1 Event-driven programming Chapter 5 covers event-driven programming. Events are user or condition driven and so each event.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Beginning Animation. Storyboard An Invitation to Dinner 1.Marlin and Dory (two small fish) are swimming and talking. 2.A shark (Bruce) swims up behind.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Programming: Simple Control Structures
Chapter 3: Decisions and Loops
Programming: Simple Control Structures
While: Indefinite Loops
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Control Structures
Repetition Control Structures
Programming: Simple Control Structures
IF if (condition) { Process… }
Doing things more than once
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Python While Loops.
Ch 9 Lists In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing the same.
Event-driven programming
Programming: Simple Control Structures
Presentation transcript:

Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While

Fall 2007ACS-1805 Ron McFadyen2 While A while loop is executed as long as some condition is true – also called a conditional loop or indefinite loop) Used in situations where we don’t know how many times a loop should execute, but we do know the condition for it to execute. Generally, we expect a while to terminate when something in the world causes the expression to be false. However, it could be coded such that it executes forever… an infinite loop

Fall 2007ACS-1805 Ron McFadyen3 While

Fall 2007ACS-1805 Ron McFadyen4 Text Example The Shark/Goldfish Chase Scene.

Fall 2007ACS-1805 Ron McFadyen5 Problem The problem is how do we get the shark to chase the goldfish in a chase-like action? The shark should not immediately catch the goldfish (otherwise, there would be no chase). The goldfish (assuming self-preservation instincts) should appear to be fleeing.

Fall 2007ACS-1805 Ron McFadyen6 Solution To create a chase scene, At the same time, the shark will swim a short distance toward the fish and the fish will swim a short distance away from the shark. The fish will flee. As long as the goldfish is still 0.5 meters away from the shark, repeat the actions.

Fall 2007ACS-1805 Ron McFadyen7 Storyboard chase While the goldfish is more than 0.5 meters away from the shark Do in order shark point at the goldfish Do together shark swim (toward the goldfish) goldfish flee (away from the shark) shark eat (the goldfish) Complex actions – become procedures themselves

Fall 2007ACS-1805 Ron McFadyen8 chase While the goldfish is more than 0.5 meters from the shark Do in order Point the shark at the goldfish Do together shark swim goldfish flee shark eat (goldfish) swim tDo in order urn torso left and move forward turn torso right and move forward turn torso left and move forward flee Do together wiggle tail move to random location Eat Parameter: what Do in order shark points at what shark opens jaw and what disappears shark closes jaw