New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.

Slides:



Advertisements
Similar presentations
Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
Advertisements

CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
CS0004: Introduction to Programming Repetition – Do Loops.
New Mexico Computer Science For All
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
New Mexico Computer Science For All Local Variables in Netlogo Maureen Psaila-Dombrowski.
Repeating Actions While and For Loops
REPETITION (loops or iteration) Schneider: Sec. 6.1 & 6.3.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
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.
Flow of Control Loops – Chapter 3.2. Java Loop Statements: Outline the while Statement the do-while Statement the for Statement.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Copyright © Texas Education Agency, Computer Programming For Loops.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Simple Python Loops Sec 9-7 Web Design.
New Mexico Computer Science For All Statements and Expressions in NetLogo Maureen Psaila-Dombrowski.
CPS120 Introduction to Computer Science Iteration (Looping)
Repetition & Loops. One of the BIG advantages of a computer: ­It can perform tasks over and over again, without getting bored or making mistakes (assuming.
CPS120 Introduction to Computer Programming The Programming Process.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
1 CSCI N201 Programming Concepts and Database 9 – Loops Lingma Acheson Department of Computer and Information Science, IUPUI.
New Mexico Computer Science For All Creating Turtles Maureen Psaila-Dombrowski.
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
Controlling Program Flow with Looping Structures
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
ITM © Port, Kazman1 ITM 352 Flow-Control: Loops Lecture #8.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
PHY 107 – Programming For Science. Today’s Goal  How to use while & do / while loops in code  Know & explain when use of either loop preferable  Understand.
PYTHON WHILE LOOPS. What you know While something is true, repeat your action(s) Example: While you are not facing a wall, walk forward While you are.
Learning Javascript From Mr Saem
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Identify the Appropriate Method for Handling Repetition
Lesson 05: Iterations Class Chat: Attendance: Participation
Karel J Robot Chapter 6.
ITM 352 Flow-Control: Loops
Introducing Do While & Do Until Loops & Repetition Statements
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Looping and Repetition
CPS120: Introduction to Computer Science
Outline Altering flow of control Boolean expressions
CSC115 Introduction to Computer Programming
Java Programming Loops
Iteration: Beyond the Basic PERFORM
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
CMPT 102 Introduction to Scientific Computer Programming
CHAPTER 21 LOOPS 1.
Java Programming Loops
FLUENCY WITH INFORMATION TECNOLOGY
Chapter 4: Repetition Structures: Looping
Repetition Statements (Loops) - 2
Python While Loops.
JavaScript 101 Lesson 8: Loops.
How to allow the program to know when to stop a loop.
Looping and Repetition
Presentation transcript:

New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski

Types of Loops Already know that there are three common types of loops in most programming languages: ▫Infinite Loops ▫Counted Loops ▫Conditional Loops

Components of a Loop Loops have some properties in common: ▫Body of the loop: The portion of the code that is repeated. ▫Iteration: Number of times the loop is executed Some types of loops have other properties ▫Loop Variable: A variable that is incremented during the looping process ▫Loop Condition: A conditional (true of false) statement that is checked during looping

Infinite Loops An infinite loop repeats the body of the loop until one of the following occurs: ▫A“stop” command in the program ▫Manually turned off. ▫A runtime error. Already familiar with this in NetLogo

Counted Loops Repeated a fixed maximum number of times. Must know how many times ▫Before programming ▫Be able to calculate maximum number of times

Counted Loops in Netlogo Netlogo has a specific command for counted loops, the REPEAT command repeat Nnumber [ commands ] The commands in the square brackets [] are repeated Nnumber of times.

Example of Counted Loops Netlogo

Conditional Loops Repeated while a certain conditional statement is true. Must establish the condition statement initially and it must be true for the loop to start The condition must become false during the looping process in order for the loop to stop, otherwise the loop becomes infinite.

Conditional Loops in Netlogo Netlogo has a specific command for conditional loops, the WHILE command while [condition] [ commands ] The commands in the square brackets [] are repeated while the condition is true. When the condition becomes false, the loop is exited.

Example of Conditional Loop in Netlogo

Summary Three types of loops ▫Infinite Loops ▫Counted Loops- the REPEAT command repeat Nnumber [ commands ] ▫Conditional Loops - the WHILE command while [condition] [ commands ]