Chapter 7. Repeating Code with Loops
The three basic building blocks for creating programs are the sequential ordering of code, branches (to make decisions), and loops (to run one or more instructions repetitively). Rather than write one long set of instructions to accomplish a task, a loop lets you write a shorter set of instructions that runs multiple times.
Suppose your program needs to ask for a password from the user before granting access. You could write a bunch of code that keeps checking for a valid password, but this gives you no idea ahead of time how many times someone may try to type in a valid password. With a loop, you just need to write one set of instructions for checking the validity of a password and, if it's valid, granting ...
Get Mac Programming for Absolute Beginners now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.