Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski."— 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 ]


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

Similar presentations


Ads by Google