Swift 循环语句

 // 循环语句

        for var i = 0 ;i < 5 ;i++ {

            

            print("i = \(i)")

        }

        

        var j = 0

        for j = 0; j < 10; j++ {

            

            print("j = \(j)")

            

        }

        

        // for in 的第一种用法

        // 1.遍历字符串

        let str = "qwertyu"

        

        for temp in str.characters {

            

            print("temp = \(temp)")

        }

        

        

        for temp1 in 1...6 {

            print("temp1 = \(temp1)")

        }

        

        // while 语句

        /*

        格式

        

        while  布尔值

        

        说明

        

        只有当while 后面的布尔值为false ,才停止 while语句,否则一直执行while语句

        */

        

        var x = 0

        

        while (x < 3)

        {

            print("x = \(x)")

            

            x++

            

        }

        

        // repeat while

        /*

        格式:

        repeat {} while 布尔值

        

        说明:

        1:现在执行 repeat 语句

        2:然后在执行while 语句

        3:如果while语句后面的布尔值为false 就停止repeat  while语句,否则就一直执行repeat  while语句

        */

        

        var y = 0

        repeat {

            

            y = y + 1

            

            print("y = \(y)")

            

        }while (y < 5)

posted on 2015-12-28 17:58  哈利波特大  阅读(169)  评论(0)    收藏  举报