Latest web development tutorials

Swift for-in loop

Swift cycle Swift cycle

Swift for-in loop to iterate a collection of all the elements which, for example, range from the digital representation of elements in the array, a string of characters.

grammar

Syntax Swift for-in loop as follows:

for index in var {
   循环体
}

flow chart:

Examples

import Cocoa

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

for index in someInts {
   print( "index 的值为 \(index)")
}

The above program execution output is:

index 的值为 10
index 的值为 20
index 的值为 30

Swift cycle Swift cycle