1 / 11

New Mexico Computer Science For All

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.

mapes
Download Presentation

New Mexico Computer Science For All

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. 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

  4. 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

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

  6. 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.

  7. Example of Counted Loops Netlogo

  8. 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.

  9. 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.

  10. Example of Conditional Loop in Netlogo

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

More Related