Repeating Actions.

Slides:



Advertisements
Similar presentations
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Repetition Structures
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:
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.
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Getting started with Alice Adapted from presentations by Jenna Hayes, Duke University Donna Gavin, UWP Computer Science and Software Engineering.
Poses Tutorial Alex Boldt Under the direction of Professor Susan Rodger Duke University July 2015.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Mathematical Expressions, Conditional Statements, Control Structures
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
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.
Today’s Agenda 1.Collect Pre-Lab 3 2.Alice Programming Assignment 3.Built-in Functions 4.Expressions 5.Control Structure 6.Assign pair programming teams.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
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.
ForLoopsInAlice1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009 Counted (For) Loops in Alice.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
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 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:
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Getting Started With Alice: The Basics. Step 1: Background Open up Alice, and choose a background for your Alice world. Your world is something you can.
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
Chapter 4 Repetition Statements (loops)
Teaching Characters to Walk: Learning Methods, Part 1
Programming: Simple Control Structures
Getting started in Alice
Chapter 3: Decisions and Loops
Putting Objects in Motion
Programming: Simple Control Structures
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Simple Control Structures
Control Structures
Repetition Control Structures
Organizing common actions
Loops and Switches Pre-Quiz
Programming: Simple Control Structures
Doing things more than once
Repetition: Definite Loops
Michelle Venable-Foster Barb Ericson Jan 2007
Programming: Simple Control Structures
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Counted (For) Loops in Alice
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Simple Control Structures
Repetition: Definite Loops
Programming: Simple Control Structures
Professor Susan Rodger
Professor Susan Rodger
Programming: Simple Control Structures
Presentation transcript:

Repeating Actions

What will we learn today? Repeated Actions Need for Repetition Repetition with Loop Nested Loops

Repeated Actions in Real Life Consider those daily actions When we talk, we simply open and close our months repeatedly a counted number of times When we walk, we move our legs forward and backward as we move a counted number of steps

Need for Repetition Consider a situation in which a man walks 5 steps forward towards a palm tree The man’s legs walk a step with each meter that he moves forward (if man moves forward 5 meters, his legs walking occur 5 times) One possible way is to animate 5 steps But, what if we want to repeat the walking action 20 times (becomes tedious and boring, isn’t it??) We can use clipboard. But it will be a bit tedious copying and dragging block of instruction several number of times

Repetition with Loops An easy way to do this is by using a loop statement The Loop Statement Is a simple way to repeat an action a counted number of times Is used to execute a block of instructions again and again (limited number of times) Is quick and easy to write and also easy to understand A count is used to describe the number of times a loop/action(s) repeats

Hide and Seek Example with Loops Remember the “hide and seek” example we did in the methods lecture Remember how many times we had to animate(copy and past) the actions Painful and tedious wasn’t it!!! Now, the torture is over and we will use loops to make our lives simpler

Repetition with Loop We have repeated actions in ‘Turn Around’ methods and in the ‘world.myfirst’ method To create a loop in a program Drag a loop tile into the editor inside the do-in order block of ‘world.myfirst’ method Choose other and enter number 3 in the popup menu Drag the ‘world.seekCat’ method into the loop statement Inside the do-together block make two loops for the turning around methods A loop can be executed only a whole number of times

Nested Loops A loop can be nested inside another loop (a loop is placed inside other loop) Remember, the ‘move around’ method was used to make a complete turn around the tree (which requires repeating the moving a step and turning right actions ten times) To make 3 complete turns we need to repeat the previous action 3 times Loop 3 times Loop 10 times Move Around

Nested Loop The second loop ‘Loop 10 times’ is called a nested loop It will fully execute each time the outer loop ‘loop 3 times’ executes once The count of the outer loop is 3, and the count of the inner loop is 10 The inner loop will execute 10 times for each of the 3 executions of the outer loop The moving around action will occur 30 (3*10) times in total Loop 10 times Move Around

The Result Loop Statement

Turn Around methods with Loops

Let’s Work with Alice Write an animation where an Arabian man in his tent serves coffee to his guests Create a method ‘fill-inCups’ in which the host man holding the dallah (middle east) and fill-in 3 empty cubs in the tray (loop 3 times) Create a method ‘serveCoffee’ where the host man serves his guests (loop 2 times) Develop the animation for this story