Latest web development tutorials

Swift cycle

Sometimes, we may need to repeatedly perform the same piece of code. Under normal circumstances, the statements are executed sequentially: the first statement in the function executed first, followed by a second statement, and so on.

Programming languages ​​provide various control structures more complex execution paths.

Loops allow us to repeatedly execute a statement or group of statements, the following is the most programming languages ​​loop flow chart?:

Loop structure

Type of cycle

Swift language provides the following cycle types. Click on the link to view a detailed description of each type:

Type of cycle description


Traversing a collection of all the elements which, for example, range from the digital representation of elements in the array, a string of characters.

for loop

To repeat a series of statements until reaching certain conditions are fulfilled, usually after each cycle is completed by increasing the value of the counter to achieve.

while loop

A series of statements to run if the condition is true, will run repeatedly until the condition becomes false.

repeat ... while loop

While a similar statement before the difference is that the loop condition is determined, the first code block is executed the first cycle.

Loop control statements

Loop control statements change the order of execution of your code, through which you can jump code. Swift following loop control statements:

Control statements description

continue Statement

Tell a loop iteration immediately stop this cycle and start again the next iteration.

break statement

Interrupt the current cycle.

fallthrough statement

If a case after the implementation, continue with the following case, it requires the use of fallthrough (through) keyword.