Loops (Repeating Code)
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).
For Loop Syntax
While Loop Syntax
Do While Syntax
Image by Author
Image by Author
Image by Author
Last modified 2yr ago
Copy link