For-In Loops multiple conditions

前端 未结 5 1991
礼貌的吻别
礼貌的吻别 2021-01-18 02:34

With the new update to Xcode 7.3, a lot of issues appeared related with the new version of Swift 3. One of them says \"C-style for statement is deprecated and will be remove

5条回答
  •  萌比男神i
    2021-01-18 02:50

    You can use && operator with where condition like

    let arr = [1,2,3,4,5,6,7,8,9]
    
    for i in 1...arr.count where i < 5  {
        print(i)
    }
    //output:- 1 2 3 4
    
    for i in 1...100 where i > 40 && i < 50 && (i % 2 == 0) {
         print(i)
    }
    //output:- 42 44 46 48
    

提交回复
热议问题