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.

Slides:



Advertisements
Similar presentations
Recursion Alice.
Advertisements

AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
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.
While: Indefinite Loops Sec 8-14 Web Design. Objectives The student will: Understand what an Indefinite Loop is Understand how create an indefinite loop.
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
CompSci 18S Recursion Dec 4, 2006 Prof. Susan Rodger.
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.
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.
Horse race © Horse race: rules 1.Each player chooses a horse and puts it into a stall. Write your name next to the.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 7 Repetition.
Fall 2008ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
Programming with Alice Advanced topics – Demo. Overview of topics Recursion Random Numbers Variables Arrays.
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.
Fall 2009ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Recursion1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Jan 2010 Recursion in Alice.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Bill's Amazing Content Rotator jQuery Content Rotator.
Apostles Chess Club Session Three. Chess Piece Symbols The symbols shown above are the ones most used when showing chess pieces in print or on the internet.
CompSci 4 Chap 7 Sec 2 Apr 7, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
CompSci 4 Chap 8 Sec 1 Nov 17, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Four Fundamental Pieces Instruction Control Structure Function Expression.
W 2 L 1 sh 1 C lessons LessonSubjectBook Week 1 lesson 1Objects, names Week 1 lesson 2Statements, layout Week 2 lesson 1Functions, decomposition Week 2.
© Jalal Kawash Programming Peeking into Computer Science 1.
For loops in programming Assumes you have seen assignment statements and print statements.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
ITP © Ron Poet Lecture 7 1 Repetition. ITP © Ron Poet Lecture 7 2 Easing Repetitive Tasks  Many computing task are repetitive.  Checking all known foods.
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.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
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.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Programming: Simple Control Structures Sec 46 Web Design.
February 25,  The BDE(Begin-During-End) event.  Worksheet – Exercise # 9 Instructions  2nd Period Test.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Chapter 7 JavaScript: Control Statements, Part 1
Programming: Simple Control Structures
Programming: Simple Control Structures
Recursion Alice.
While: Indefinite Loops
Let's Race! Typing on the Home Row
Recursion Alice.
Programming: Simple Control Structures
Alice in Action with Java
Doing things more than once
MSIS 655 Advanced Business Applications Programming
Programming: Simple Control Structures
Looping and Random Numbers
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Decision Statements.
Presentation transcript:

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 is needed For example, in a board game like chess or checkers, we don’t know exactly how many moves it will take for a player to win or lose the game – all we know is that several moves will be needed.

Indefinite Repetition In programs where a count of repetitions is not known (indefinite), we can use one of two repetition control mechanisms: Recursion While statement This session focuses on Recursion.

Recursion Many of the pieces we use to create a program are identified by using special words. For example, Do in order Do together If/Else Loop Recursion is not a program statement with a special word that identifies it as part of the programming language. Recursion means that a method (or a function) calls itself.

Example – horse race A carnival style horse race. In repeated moves, one horse is randomly selected to move forward. The selected horse “runs” straight ahead to the finish line. A horse is the winner if it gets to the finish line before any other horse. When one horse wins, the game ends.

Storyboard "do everything again" means that the entire method should be repeated. To do everything again, the method calls itself. race If one of the horses has won the winner says, “I won!!!” Else randomly choose one horse and move it forward a small amount do everything again

Stepwise Refinement race If one of the horses has won the winner says, “I won!!!” Else randomly choose one horse and move it forward a small amount call race method isGameOver? whichHorseWon?moveRandomHorseForward

Assignment Read Chapter 8 Vocabulary Words HorseRace Example Towers Example Page 253, #2 Reversal Exercise (worksheet)