2.7 Swift逻辑运算符

来源:互联网 发布:俄罗斯人 知乎 编辑:程序博客网 时间:2024/05/29 16:14

  /**

         逻辑运算符

         &&

         

         ||

         

         !

         */

        

        let allowLeave =false

        

        if!allowLeave

        {

            print("NO")

        }

        

        /**

         不可以这样

         Binary operator '&&' cannot be applied to two 'Int' operands

         */

//        var a = 11

//        if a && 11

//        {

//            print("YES")

//        }


        /**

         && 要求两侧的表达式必须是布尔值

         */

        let a =true

        let b =false

        

        print("------->")

        if a&& b

        {

            print("YES")

        }

        

        if a|| b

        {

            print("YES")

        }

        

        let age =20

        let height =186

        

        if age >30 && age <40 && height >170

        {

            print("YES")

        }


0 0