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
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Advertisements

1 Fall 2009ACS-1805 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique shown in text) Directed.
Repetition Structures
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2009ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Repeating Actions While and For Loops
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.
COMP 14 Introduction to Programming Miguel A. Otaduy May 21, 2004.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
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.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 7 Repetition.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
1 Fall 2008ACS-1903 Ch 4 Loops and Files while loop do-while loop Other topics later on …
1 Fall 2007ACS-1903 Ch 4 Loops and Files Increment & decrement statements while loop do-while loop Other topics later on …
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
CPS120 Introduction to Computer Science Iteration (Looping)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
1 Fall 2007ACS-1903 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique) Text presents one of these.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
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)
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.
CS320n –Visual Programming Definite / Counted Loops (Slides 7-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Repetition: Definite Loops Sec 53 Web Design. Objectives The Student will: Understand loops and why they are used Understand definitive loops Know how.
Repetition Repetition allows you to repeat an operation or a series of operations many times. This is called looping and is one of the basic structured.
Fundamental Programming Fundamental Programming More on Repetition.
Language Find the latest version of this document at
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
1 Fall 2009ACS-1903 Ch 4 Loops and Files while loop do-while loop for loop Other topics later on …
While ( number
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
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.
Chapter 6 Controlling Program Flow with Looping Structures.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Chapter 4 Repetition Statements (loops)
Chapter 3: Decisions and Loops
Lesson 05: Iterations Class Chat: Attendance: Participation
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Karel J Robot Chapter 6.
Chapter 5: Loops and Files.
Chapter 5: Repetition Structures
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Learning About the Loop Structure (continued)
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Repetition: Definite Loops
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Counted (For) Loops in Alice
Chapter 8: More on the Repetition Structure
3.5- The while Statement The while statement has the following syntax:
Repetition: Definite Loops
Repetition: Definite Loops
FLUENCY WITH INFORMATION TECNOLOGY
PROGRAM FLOWCHART Iteration Statements.
Building Java Programs
CSC1401 Manipulating Pictures 2
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 Loop A definite loop is executed a specified number of times (also referred to as a counted loop) Also discussed back in Ch 3, page 63+ Text: 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.

Fall 2007ACS-1805 Ron McFadyen3 Flowchart for Loop index < limit? Loop action(s) false true Loop action(s) executed as an index variable starts at some initial value is incremented by some increment before a next iteration goes up to some limit Set index to initial value Increment index

Fall 2007ACS-1805 Ron McFadyen4 bunny.hop

Fall 2007ACS-1805 Ron McFadyen5 bunny.hop vs Less code More flexible Easier to comprehend

Fall 2007ACS-1805 Ron McFadyen6 Infinite Loop In an animation we may want for some activity to never stop, unless the world stops playing

Fall 2007ACS-1805 Ron McFadyen7 Nested Loops Each time the ferris wheel makes a revolution the smaller wheels must turn too The inner loop is executed twice (in this example) for each iteration of the outer loop