Easy Tutorial
❮ Swift While Loop Swift Protocols ❯

Swift for Loop

Swift Loops

>

Swift for loop is used to repeatedly execute a series of statements until a specific condition is met, typically by incrementing a counter after each loop completion.

Syntax

The syntax for a Swift for loop is as follows:

for init; condition; increment {
   loop body
}

Parameter Explanation:

Flowchart:

Example

import Cocoa

var someInts:[Int] = [10, 20, 30]

for var index = 0; index < 3; ++index {
   print("Value at index [\(index)] is \(someInts[index])")
}

The output of the above program is:

Value at index [0] is 10
Value at index [1] is 20
Value at index [2] is 30

Swift Loops

❮ Swift While Loop Swift Protocols ❯