「Swift」for in文で整数型、浮動小数点型配列の要素を取得

書式
定義 let 配列名][データ型] =[xxx]
使い方
for 変数名 in 配列名 {xxx}
使用例

//String型配列
let strArray:[String] = ["study", "skill", "become", "smart"]
print("String型配列の要素を出力")
for str in strArray {
    print(str)
}

//Double型配列
let dbArray :[Double] = [3.14, 4.25, 6.78]
print("Double型配列の要素を出力")
for db in dbArray {
    print(db)
}

//int型配列
let intArray :[Int] = [14, 5, 8,35]
print("int型配列の要素を出力")
for i in intArray {
    print(i)
}

結果
$ swift g.swift
String型配列の要素を出力
study
skill
become
smart
Double型配列の要素を出力
3.14
4.25
6.78
int型配列の要素を出力
14
5
8
35

Swift

Posted by arkgame