Skip to Content
Swift OS X Programming for Absolute Beginners
book

Swift OS X Programming for Absolute Beginners

by Wallace Wang
August 2015
Beginner content levelBeginner
572 pages
12h 22m
English
Apress
Content preview from Swift OS X Programming for Absolute Beginners

Chapter    8

Repeating Code with Loops

The basic goal of programming is to write as little code as possible that does as much as possible. The less code you write, the easier the program will be to understand and modify later. The more your code does, the more powerful your program will be.

One way to write less code is to reuse code stored in functions. A second way to reuse code is through loops. A loop runs one or more lines of code multiple times, thereby eliminating the need to write multiple, redundant lines of code.

For example, if you wanted to print a message five times, you could write the following:

print ("Hello")print ("Hello")print ("Hello")print ("Hello")print ("Hello")

This is tedious but it will work. However, if you suddenly ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Swift for Absolute Beginners

Swift for Absolute Beginners

Gary Bennett, Brad Lees

Publisher Resources

ISBN: 9781484212332Purchase book