Loops (Repeating Code)
Last updated
Last updated
Another method of control is repetition. You wouldn't want to write all of the code that does something one hundred times. That would be like writing the same sentence one hundred times. For that, we ask the computer to do something repeatedly. We will look at count-controlled for
loops and condition-controlled while
or do
loops.
Khan Academy employs something I really like
The Three Loop Questions
1. What do I want to repeat?
2. What do I want to change each time?
3. How long should it repeat?
Select one of the following to learn more about the different types of loops (syntax listed below for quick reference).