0
1

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 3 years have passed since last update.

ネストループをラベルで指定して抜ける方法

Last updated at Posted at 2020-06-21
struct Hoge {
    let test: [String]
    let test1: [String]
}

let hoge = Hoge.init(test: ["3","3","3","4","3","3"] , test1: ["3","3","3","4","3","3"])

outer: for i in hoge.test {
    inner: for t in hoge.test1 {
        if i == t {
            print("inner")
            break inner
        } else {
            print("outer")
            break outer
        }
    }
}
inner
inner
inner
outer

for文の前にラベルをつけることで抜ける際にどのループ文を抜けるのか指定することができる。
While文やswitch文でも使うことはできる。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?