重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

06.swift.if和三目语句基本使用

/*

从策划到设计制作,每一步都追求做到细腻,制作可持续发展的企业网站。为客户提供成都网站建设、网站建设、网站策划、网页设计、域名与空间、虚拟主机、网络营销、VI设计、 网站改版、漏洞修补等服务。为客户提供更好的一站式互联网解决方案,以客户的口碑塑造优易品牌,携手广大客户,共同发展进步。

Swift: if语句基本使用

if 条件表达式 {指令}   if 条件表达式 {指令} else{指令}

0.if后的圆括号可以省略

1.只能以bool作为条件语句

2.如果只有条指令if后面的大括号不可以省略

*/

var age1:Int

var age2:Int

var max:Int

max = age2;

if age1 > age2

{

    max = age1

}

print(max)

if age1 > age2

{

    max = age1;

}else

{

    max = age2;

}

print(max)

var score = 99.9;

if score >= 90

{

    print("优秀")

}else if score >= 60

{

    print("良好")

}else

{

    print("不给力")

}

// 1.if的使用

// 1> if后面的()可以省略

// 2> 判断句不再有非0即真.必须有明确的Bool值:true/false

let a = 10

if a != 0 {

   print("a不等于0")

} else {

    print("a等于0")

}

// 2.if elseif的使用

let score = 88

if score < 0 || score > 100 {

   print("没有意义的分数")

} else if score < 60 {

    print("不及格")

} else if score < 80 {

    print("及格")

} else if score < 90 {

    print("良好")

} else if score <= 100 {

    print("优秀")

}

// 3.三目运算符

let m = 40

let n = 30

var result = 0

//if m > n {

//    result = m

//} else {

//    result = n

//}

result = m > n ? m : n

print(result)


网页名称:06.swift.if和三目语句基本使用
标题链接:http://cqcxhl.cn/article/jhdjij.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP