27
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swiftのfor-in文で"1..<3"と"1...3"のちがい

Last updated at Posted at 2014-06-15

Xcode6 beta3での変更点

Xcode6 beta3 で 「x以上y未満」を表すfor-in文の記法が変更されました。

  • beta2まで:1..3
  • beta3から:1..<3
    すごくわかりやすくなりましたね。
    「x以上y以下(yを含む)」はbeta3以降も「1...3」のままです。
    Swift Language Changes in Xcode 6 beta 3

for i in 1..<3 実行例

test.swift
for i in 1..<3 {
    println("value \(i)")
}

実行結果

value 1
value 2

for i in 1...3 実行例

test.swift
for i in 1...3 {
    println("value \(i)")
}

実行結果

value 1
value 2
value 3

まとめ

  • for i in x..<y の場合は、yは含まない
  • for i in x...y の場合は、yを含む
27
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?