Fast is really a effective and spontaneous programming language for macOS, iOS, watchOS and tvOS...

Page 61

Swift

index = index + 1 }while index < 20 When the above code is executed, it produces the following result: Value of index is 10 Value of index is 11 Value of index is 12 Value of index is 13 Value of index is 14 Value of index is 15 Value of index is 16 Value of index is 17 Value of index is 18 Value of index is 19

Loop Control Statements Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Swift supports the following control statements. Click the following links to check their detail. Control Statement

Description

continue statement

This statement tells a loop to stop what it is doing and start again at the beginning of the next iteration through the loop.

break statement

Terminates the loop statement and transfers execution to the statement immediately following the loop.

fallthrough statement

The fallthrough statement simulates the behavior of swift switch to C-style switch.

Swift – continue Statement The continue statement in Swift tells a loop to stop what it is doing and start again at the beginning of the next iteration through the loop. For a for loop, the continue statement causes the conditional test and increments the portions of the loop to execute. For while and do...while loops, the continue statement causes the program control to pass to the conditional tests. 49


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.