CompSci 4 Chap 8 Sec 1 Nov 17, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.

Slides:



Advertisements
Similar presentations
Recursion Alice.
Advertisements

AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
Repetition control 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.
CompSci 18S Recursion Dec 4, 2006 Prof. Susan Rodger.
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.
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 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.
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
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.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
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.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
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.
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
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
CompSci 4 Chap 4 Sec 1 Sept 15, 2005 Prof. Susan Rodger.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
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.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
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.
CompSci 4 Chap 5 Sec 2 Oct 9, 2008 Prof. Susan Rodger.
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.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Programming: Simple Control Structures Sec 46 Web Design.
CompSci 4 Chap 9 Sec 1 October 28, 2010 Prof. Susan Rodger.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
February 25,  The BDE(Begin-During-End) event.  Worksheet – Exercise # 9 Instructions  2nd Period Test.
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 November 4, 2010 Prof. Susan Rodger.
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.
CS320n – Elements of Visual Programming List Search Mike Scott (Slides 9-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Programming: Simple Control Structures
Chapter 3: Decisions and Loops
Programming: Simple Control Structures
Recursion Alice.
While: Indefinite Loops
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Let's Race! Typing on the Home Row
Recursion Alice.
<INSERT_WITTY_QUOTE_HERE>
Programming: Simple Control Structures
The structure of programming
Thinking procedurally
Presentation transcript:

CompSci 4 Chap 8 Sec 1 Nov 17, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas

Announcements Read Chapter 10, Section 1 and 2 for next time –Sec 1 is a review of variables –Sec 2 introduces arrays Note: We will NOT cover Chap 8, Sec 2

What we will do today Lecture on Chap 8 Section 1 –Recursion Classwork

Repetition Sometimes don’t know exactly how many times a block of instructions should be repeated –Repeat until some condition is true –Repetition gets closer to condition being true Example – Chess, don’t know when in advance how many moves til game ends

Indefinite Repetition When number of repetitions is indefinite –While statement – previously –Recursion - today

Recursion Many times a structure is identified by a special word –Do in order –Do Together –If/Else –Loop Recursion –Is NOT a program statement with a special word –Recursion means a method (or function) calls a clone of itself

Example – horse race Horse race One horse randomly selected to move forward, repeatedly First horse to finish line is winner

Storyboard “do everything again” means the entire method should be repeated – this is recursion race if one of the horses has won winner says “I won” else randomly choose horse and move do everything again

“Do everything again” - Call race method Recursion means that a method calls a “clone of itself” race if one of the horses has won winner says “I won” else randomly choose horse and move call the race method

Stepwise Refinement race if one of the horses has won winner says “I won” else randomly choose horse and move call the race method isGameOver? whichHorseWon? moveRandomHorseForward

isGameOver and WhichHorseWon isGameOver –Is the finish line < 0.5 meters in front of any horse? If so, game is over –Returns true if game is over WhichHorseWon –Which horse is within 0.5 meters of finish line? – Returns the horse that won

moveRandomHorseForward To choose horse to move forward, use built-in random selection function

race method Uses recursion Where is the “way out”?

Classwork today Written: raceHorse move recursive statement Write recursive method BunnysMeet – Two bunnys repeatedly hop towards each other at the same time, as long as they are > 3 meters apart. –When bunnys are close (<= 3 meters apart but still at least 2 meters apart, 1 bunny hops once. –When bunnys are too close to jump any more, they bow to each other once at the same time. Download file: BunnysInGarden