// //1.赋值运算符
// var str="Hello,playground"
// var newStr=str
// let(a,b,c)=(1,2,3)
// print(a)
// print(b)
// print(c)
// //2.算术运算符
// var a:Int = 8
// var b:Int = 2
// print(a+b)
// print(a-b)
// print(a*b)
// print(a/b)
// //字符串拼接运算符
// var str1:String="Hello,"
// var str2:String="world!"
// print(str1+str2)
// //取余运算符号
// var a:Int=9
// var b:Int=2
// print(a%b)
//自增/减运算符
// var a=3
// a+=1
// print(a)
// let b=a
// a-=1
// let c=a
// print(c)
// //3.关系运算符
// var a=3,b=6
// a == b
// a != b
// a > b
// a < b
// a >= b
// a <= b
// if a == b{
// print("a is \(a),b is \(b),they are equal.")
// }else{
// print("a is \(a),b is \(b),they are not equal!")
// }
// //4.逻辑运算符
// var on:Bool=false
// if !on{
// print("the light is off")
// }
// //与运算符
// var on:Bool=false
// var sunshine:Bool
// var indoors:Bool
// func lightControl(sunshine:Bool,indoors:Bool){
// on = (!sunshine) && indoors
// if !on{
// print("turn light off")
// }else{
// print("turn light on")
// }
// }
// sunshine = false
// indoors = true
// lightControl(sunshine:sunshine,indoors:indoors)
// //或运算符
// var off:Bool=false
// var sunshine:Bool
// var indoors:Bool
// func lightControl(sunshine:Bool,indoors:Bool){
// off=sunshine||(!indoors)
// if off{
// print("turn light off")
// }else{
// print("turn light on")
// }
// }
// sunshine=false
// indoors=true
// lightControl(sunshine:sunshine,indoors:indoors)
// //5.三元运算符
// let contentHeight=100
// let bottomHeight=20
// var hasHeader=true
// let pageHeight=contentHeight+bottomHeight+(hasHeader ?30:10)
// print(pageHeight)
// // 6.区间运算符
// // 区间运算符
// for i in 0...3{
// print(i)
// }
// for i in 0..<3{
// print(i)
// }
// //7.控制流
// //区间循环1
// for i in 1...6{
// print("No.\(i);")
// }
// //区间循环2
// for _ in 1...6{
// print("Execute!")
// }
// //while循环
// var i=0
// while i<5{
// print("i=\(i)")
// i+=1
// }
// // //repeat-while循环
// var i=0
// repeat{
// print("i=\(i)")
// i+=1
// }while i<5
// //if-else
// var season="autumn"
// if season == "spring"{
// print("All trees turn green.")
// }else if season == "summer"{
// print("It's too hot.")
// }else if season == "autumn"{
// print("Leaves are falling.")
// }else{
// print("Snow will come!")
// }
// //switch
// enum month{
// case January
// case February
// case March
// case April
// case May
// case June
// case July
// case August
// case September
// case October
// case November
// case December
// }
// var curMonth = month.February
// switch curMonth{
// case month.January:print("the first month of a year")
// case month.February:print("There is the most important festival in this month")
// case month.April,month.May,month.June:print("month of the second season")
// default:print("\(curMonth) doesn't match any case")
// }
// //switch匹配范围
// var curMonth=5
// switch curMonth{
// case 1...3:print("the first season")
// case 4...6:print("the second season")
// default:print("the latter half of the year.")
// }
// //switch匹配元组
// var calssInfo=(2015,"Computer Science")
// switch calssInfo{
// case(2016,"Computer Science"):print(calssInfo)
// case(2016,_):print("2016's other class")
// case(_,"Computer Science"):print("Computer Science Class in other year")
// default:print("we don't care this class information")
// }
// //值绑定
// var calssInfo = (2012,"Medicine")
// switch calssInfo{
// case (let year,"Computer Science") :
// print("Year\(year)'s Computer Science Class")
// case (2016,let course) :
// print("2016's class\(course)")
// case let (year,course) :
// print("Class \(course) in year\(year)")
// }
// //where 语句
// switch calssInfo{
// case let (year,_) where year == 2015:
// print("Class\(year) in year 2015")
// case let(_,course) where course == "Medicine":
// print("Class Medicine in year \(course)")
// case let(year,course):
// print("Class \(course) in year\(year)")
// }
// //控制转义语句1
// for i in 1...6{
// if i == 4{
// continue
// }
// print("No.\(i)")
// }
// //控制转义语句2
// for i in 1...6{
// if i == 4{
// break
// }
// print("No.\(i)")
// }
// //for 循环
// var sum = 0
// for number in 1...100{
// sum+=number
// }
// print("Sum of 1+2+...+99+100=\(sum)")
// var number=0
// var sum=0
// while number <= 100{
// sum += number
// number += 1
// }
// print("Sum of 1+2+...+99+100=\(sum)")
// var number=0
// var sum=0
// repeat{
// sum += number
// number += 1
// }while number<=100
// print("Sum of 1+2+...+99+100=\(sum)")
// var score = 88
// if score < 60{
// print("Fail")
// }else if score < 70{
// print("Pass")
// }else if score < 80{
// print("Common")
// }else if score < 90{
// print("Good")
// }else{
// print("Excellent")
// }
// var grade=99
// switch grade{
// case 0...59 : print("Fail")
// case 60...69 : print("Pass")
// case 70...79 : print("Common")
// case 80...89 : print("Good")
// case 90...100 : print("Excellent")
// default :
// print("Unreasonable Score!")
// }
// var subject="Math"
// var grade="Excellent"
// var subjectInfo=(grade,subject)
// switch subjectInfo {
// case ("Fail",_):print("Fail")
// case ("Pass",_):print("Pass")
// case ("Excellent", "Math"):print("Math is Excellent")
// case ("Excellent", "Physics"):print("Physics is Excellent")
// default:print("Common or Good")
// }
// var subjectInfo = ("Pass","Math")
// switch subjectInfo {
// case ("Fail",let subject):print("Subject \(subject) is Fail")
// case ("Pass",let subject):print("Subject \(subject) is Pass")
// case ("Excellent","Math"):print("Math is Excellent")
// case ("Excellent","Physics"):print("Physics is Excellent")
// default:print("Common or Good")
// }
// var subjectInfo = ("Excellent","Physics")
// switch subjectInfo{
// case("Fail",let subject):print("Subject \(subject) is Fail")
// case("Pass",let subject):print("Subject \(subject) is Pass")
// case let(grade,subject) where (subject == "Math" || subject == "Physics") && grade == "Excellent":
// print("\(subject) is \(grade)")
// default:print("Common or Good")
// }
// var product=2
// var count=2
// while count<3{
// count+=1
// if product>0{
// print("count is \(count),product is \(product).")
// break
// }
// product *= count
// }
// print("Cycle is stopped!")
// print("count is \(count),product is \(product).")
// var product=2
// var count=2
// while count<5{
// count+=1
// if product>0{
// print("count is \(count),product is \(product).")
// continue
// }
// product = product * count
// }
// print("Cycle is stopped!")
// print("count is \(count),product is \(product).")