swift-for 循环


import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        demo1()
    }

    
    func demo1()  {
        // 变量在[0,5) 循环
        
        for i in 0..<5 {
            print(i)
        }
        
        print("-------")
        // 变量在[0,5] 循环
        for i in 0...5 {
            print(i)
        }
        
        //Range(0..<5)
        let r1 = 0..<5
        print(r1)
        
        //ClosedRange(0...5)
        
        let r2 = 0...5
        print(r2)
        
        
       
        

    }
    
    
     // 反序便厉
     func demo2()  {

        for i in (0..<5).reversed() {
            print(i)
        }
        
    
    }

}


你可能感兴趣的:(swift-for 循环)