美文网首页
Swift - for循环/repeat-while循环

Swift - for循环/repeat-while循环

作者: GA_ | 来源:发表于2017-03-14 16:22 被阅读88次
    别看我 我只是过往云烟
    
    swift 3.0
    // for-each循环
    (1...10).forEach {
        print($0)
    }
    // 反转
    for i in (1...10).reversed() {
        print(i)
    }
     
    let array = [1, 5, 3, 2, 4]
    // 遍历
    for (index, value) in array.enumerated() {
        print("\(index + 1) \(value)")
    }
    let numberOfLegs = [“spider” : 8, “cat” : 4]
    for (animalName, legCount) in numberOfLegs {
         print(animalName, legCount)
    }
    
    for i in 0 ..< attributes.count{
    
    }
    attributes.count 等于 2  打印出来 0 1
    attributes.count 等于 3  打印出来 0 1 2
    for var i = 0 ; i<5 ;i++ { 
         println("i=\(i)")           
    }
    for temp in [temp] {
    
    }
    
    for (int i = 0; i < 10; i++) {
             
    }
    
    for var index = 0; index < 3; ++index {
         print(index)
    }
    
    
    //
            var count: Int = 0
            repeat {
                print("我是repeat")
                count++
            } while count < 5
                print("END")

    相关文章

      网友评论

          本文标题:Swift - for循环/repeat-while循环

          本文链接:https://www.haomeiwen.com/subject/pxjhnttx.html