Chapter 20. Repeating Blocks
If there’s one thing that computers are good at, it’s repeating things—like little children, they never tire of repetition. They are also very fast and can do things such as process your entire list of Facebook friends in a microsecond.
In this chapter, you’ll learn how to program repetition with special repeat blocks instead of copying and pasting the same blocks over and over. You’ll learn how to send an SMS text to every phone number in a list and how to add up a list of numbers. You’ll also learn that repeat blocks can significantly simplify an app.
Controlling an App’s Execution: Branching and Looping
In previous chapters, you learned that you define an app’s behavior with a set of event handlers—events and the functions that should be executed in response. You also learned that the response to an event is often not a linear sequence of functions and can contain blocks that are performed only under certain conditions.
Repeat blocks are the other way in which an app behaves in a nonlinear fashion. Just as
else if blocks allow a program to branch, repeat blocks allow a program to loop; that is, to perform a set of functions and then jump back up in the code and do it again, ...