3
3

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でloop

Posted at


3を含む繰り返し

swift
var i = 0
for n in 1...3 {
  i+n
}

3を含まない繰り返し

swift
var y = 0
for n in 1 ..< 3 {
  y+n
}

コレクションから取り出す

swift
var y = 0
for n in 1 ..< 3 {
  y+n
}

Dictionary から取り出す

swift
let hogeDic = ["hoge":"huga"]
for (hoge,huga) in hogeDic {
  hoge + huga
}

Dictionaryからkeyだけ取り出す

swift
let hogeDic = ["hoge":"huga"]
for key in hogeDic.keys {
  key
}

Dictionaryからvalueだけ取り出す

swift
let hogeDic = ["hoge":"huga"]
for value in hogeDic.values {
  value
}

普通(?)のforループ

swift
let sizelist = ["xs", "s", "m", "l", "xl"]
for (var i = list.count ; i > 0; i--)  {
  sizelist[i - 1]
}

ラベルを付けてそこに戻ることができるっぽい 
(continue xloopでxloopの場所まで戻れる)

swift
xloop:for x in 0...5 {
  yloop:for y in 0...5 {
    continue xloop
  }
}
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?