Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Concept #2 Iteration. Is just a fancy way of saying that you would like something to repeat more than one time. It is used in any modern programming.

Similar presentations


Presentation on theme: "Programming Concept #2 Iteration. Is just a fancy way of saying that you would like something to repeat more than one time. It is used in any modern programming."— Presentation transcript:

1 Programming Concept #2 Iteration

2 Is just a fancy way of saying that you would like something to repeat more than one time. It is used in any modern programming language to make life easier on the programmer. If any of you have ever used code.org you have already used iteration in your programs without even knowing it.

3 Specifications Are the instructions that are handed off to a computer programmer telling them what they need to do. They should be CLEARLY written with little to no room for interpretation. If the programmer has any questions about the specifications they should get with whoever wrote them BEFORE they start writing their code. The abbreviation for specifications is ‘specs’.

4 Your Specs So lets assume that you are a programmer and you receive the following specs. – Create a program with a city as a background and create a sprite that patrols the city making sure it is safe. – Your sprite will patrol the city by moving back and forth across the screen. When they reach one side of the screen they will turn around and head to the other. – If they stop patrolling the city it means the city is unsafe and open to mayhem.

5 Picture of your Staring off Point

6 Pseudocode Please write down in ENGLISH how you would go about writing this code.

7 Example Code WITHOUT Iteration Notice that the first four lines would need to be repeated OVER, and OVER, AND OVER again. This makes it almost impossible to write this code because the cat will stop moving once it reaches the end of this code and the cat shouldn’t stop until the user ends the program. So how do you solve this problem?

8 Iteration You can replace all of this code with 5 lines of code. Go to the next page to see how it would look.

9 Iteration -Notice that you are simply repeating the first four lines FOREVER. -That is called a forever ‘loop’ and any block inside of it will simply repeat over and over until the program ends. -That is a very simple form of iteration.

10 Iteration -Things to note: -When you use iteration it should make your code easier to read. -When you use iteration you need fewer lines of code. -This makes it easier to code the program. -It also makes it easier to read the program.

11 Iteration There are other blocks in Scratch that can be used for iteration. Take a look at the block And the block for other examples of iteration. Remember iteration is just a fancy way of saying repeat. It’s your job as the programmer to figure out what steps you want repeated and how long they should repeat.


Download ppt "Programming Concept #2 Iteration. Is just a fancy way of saying that you would like something to repeat more than one time. It is used in any modern programming."

Similar presentations


Ads by Google