Changes

Swift Flow Control

2 bytes removed, 19:04, 2 December 2014
= The Condition-Increment for Loop
 
 
Regardless of the programming language used, application development is largely an exercise in applying logic, and much of the art of programming involves writing code that makes decisions based on one or more criteria. Such decisions define which code gets executed, how many times it is executed and, conversely, which code gets by-passed when the program is executing. This is often referred to as flow control since it controls the flow of program execution. Flow control typically falls into the categories of looping control (how often code is executed) and conditional flow control (whether or not code is executed). This chapter is intended to provide an introductory overview of both types of flow control in Swift.
Swift provides two types of for loop, namely the condition-increment for loop and the for-in loop:
=== The Condition-Increment for Loop ===
The condition-increment for loop uses the following syntax:
In the above example, the while expression will evaluate whether the myCount variable is less than 100. If it is already greater than 100, the code in the braces is skipped and the loop exits without performing any tasks.
If, on the other hand, myCount is not greater than 100 the code in the braces is executed and the loop returns to the while statement and repeats the evaluation of myCount. This process repeats until the value of myCount is greater than 100, at which point the loop exits.
== The do ... while loop ==