This module finally let us see why computers are so powerful. We can write only a few lines of code, but have the computer do relatively lots more work -- by directing it to do those lines repeatedly.
For example, on a digital music player, if you have a favorite song, you can set it to repeatedly play that song. You can imagine, the code that reads the file and plays the song is called inside a loop. In the next module, we'll see how your digital music player plays a playlist -- it uses loops as well -- but also another computing concept.
There are two forms of loops -- one that runs a fixed number of times and one that runs while a boolean expression evaluates to true (or until it evaluates to false). We can nest one loop inside another to get even more complicated, repeated behavior.
Things we learned in this module:
Questions you should be able to answer after completing this module:
[Q10.7.1]: In the code below, how many times does the HoppingBunny hop?
[Q10.7.2]: How would I write code that makes the HoppingBunny repeat the following actions 2 times: spin 3 times then hop 3 times.
[Q10.7.3] Using the code and picture below, how many times will the lunchLady move forward?
[Q10.7.4]: Assuming the zombie and lunchLady are less than 1 meter from each other and the lunchLady was moving away from the zombie and we want her to stop moving when she gets at least 5 meters away from the zombie, which condition should we use in the following while?
A.
B.
C.
D.
E. A and D
F. B and C
[Q10.7.5]: How many meters will the zombie move forward in the following code: