O'Reilly logo

Mac Programming for Absolute Beginners by Wallace Wang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required