Swift-for-in

提供:Dev Guides
移動先:案内検索

Swift-for-inループ

*for-in* ループは、数値の範囲、配列内のアイテム、または文字列内の文字などのアイテムのコレクションを反復します-

構文

Swift 4プログラミング言語の for-in ループの構文は-

for index in var {
   statement(s)
}

For-Inループ

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

for index in someInts {
   print( "Value of index is \(index)")
}

上記のコードが実行されると、次の結果が生成されます-

Value of index is 10
Value of index is 20
Value of index is 30