Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Beginning Swift

You're reading from   Beginning Swift Master the fundamentals of programming in Swift 4

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781789534313
Length 202 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Rob Kerr Rob Kerr
Author Profile Icon Rob Kerr
Rob Kerr
Kåre Morstøl Kåre Morstøl
Author Profile Icon Kåre Morstøl
Kåre Morstøl
Arrow right icon
View More author details
Toc

Loops


After the branching structures if and switch, the most common structures you'll use in your programming are looping structures, which cause your program flow to execute the same code iteratively.

The looping structures you'll learn in this section are the following:

  • for…in, which executes the same code a predetermined number of times

  • while and repeat…while, which executes code until a true condition becomes false

As with the switch control structure, there are many features and flexible options provided by these structures that make Swift more expressive and powerful than many other programming languages.

The for…in Statement

The following diagram illustrates how the for...in statement works:

Most programming languages have a for statement used to execute a code statement a certain number of times. The preceding diagram illustrates how the for...in statement works. A canonical example of a for loop in C, similar to many other C-inspired languages, is the following: ...

You have been reading a chapter from
Beginning Swift
Published in: May 2018
Publisher: Packt
ISBN-13: 9781789534313
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime