37. 範囲型
Swift #2
let range1:CountableRange = 1..<4
//半開区間
for value in range1 {
print(value)
}//1,2,3
let range2:CountableClosedRange = 1...4
//閉区間
for value in range2 {
print(value)
}//1,2,3,4
38. 範囲型
Swift #3
let range3:Range = 1.1..<4.0
let range4:ClosedRange
= 1.1…4.0
//Coutableではない
for value in range3 {
print(value)
}//コンパイルエラー
40. 範囲型
Scala #2
val range1:Range = 1 until 4
//半開区間
for (i <- range1) {
println(i)
}//1,2,3
val range2:Range.Inclusive = 1 to 4
//閉区間
for (i <- range2) {
println(i)
}//1,2,3,4