PAT - Iterations (Lesson)
Iterations
What is an iteration?
In programming, an iteration is repeating the process again and again, until something causes the process to stop.
count
The count loop is a special loop that counts to the number that you tell it and does all the instructions the number of times you indicate.
Learning More About Count
Let's learn about using the count method in Alice by watching the videos. Open your Alice and follow along, creating the code and pausing the video as necessary. This will provide you experience and notes. Part of learning to program well is to try by doing, by creating, and experimenting. So follow the information in the videos and then experiment with more yourself.
This video demonstrates how to use the basic looping, count, a method abstracted from the user, us as the programmer, but works to loop the number of times you tell it. How this works in code is hidden, we accept that it works to perform the loop the number of times required. The number of times that the loop occurs is the number of iterations of the procedure. We as the programmer write the inside of the loop, what is to happen each time the loop operates.
The video asked that you write the code for the Monkey. As you do so, try out other details and options available so that you know how they work. Later I will have the Monkey loop in my video. It may not be the same as yours, but that is okay, programmers do not always arrive at the answer the same way, yet the problem is solved. How the problem is solved is part of the creative aspect of programming. The efficiency of the solution, how well it works with memory usage in the computer and time to complete becomes part of the difference, which many times is negligible. If your Monkey loop works and is different from mine when you see mine later, it is okay. However, examine mine for different techniques or options, so that you can learn by seeing and doing.
Adding a Variable
Now that you have learned how to make a basic count loop, add a variable to be able to display the number of times the loop operates. Watch the video below to see how to add the variable to allow the Hare to "say" each loop number. We also add a math algorithm to add to the variable.
Make sure you try the addition of the variable with your portion, the Monkey portion which is yours to write.
The abstraction is the process of counting and the process of looping to access the statements multiple times.
Abstract process in count
- Loop construction
- Keeping track of the number of times the loop is processed
- On false going to the next statement after the loop
VIDEOS AND IMAGE CREATED BY GAVS .