let b = 10
var a = 5
a = b // 10
Copy the code
  • Take more than
9%4 // 1-9%4 // -1Copy the code
let three = 3
let minusThree = -three // -3
let plusThree = -minusThree // 3
Copy the code
var a = 1
a += 2 // 3
Copy the code
let name = "world"
if name == "world" {
    print("hello,world")
} else {
    print("I'm sorry \(name)")
}
Copy the code
(1,"zebra") < (2,"apple") // true 1 < 2 (3,"apple") < (3,"bird") // true apple < bird (4,"dog") == (4,"dog") // true (" blue ", 1) "(" purple", 1) / / true (" blue ", false) < (" purple ", true) / / the error bool cannot compareCopy the code
let contentHeight = 40 let hasHeader = true let rowHeight = contentHeight + (hasHeader ? 50:20) // 90Copy the code
let defaultColorName = "red"
var userDefinedColorName : String? // nil
var colorNameToUse = userDefinedColorName ?? defaultColorName // red

userDefinedColorName = "blue"
colorNameToUse = userDefinedColorName ?? defaultColorName // blue
Copy the code
Interval arithmetic
for index in 1... 5 { print("\(index) times 5 is \(index * 5)") } /* 1 times 5 is 5 2 times 5 is 10 3 times 5 is 15 4 times 5 is 20 5 times 5 is 25 */Copy the code
let names = ["Anna","Alex","Brain","Jack"] let count = names.count for i in 0.. <count { print("Person \(i + 1) is called \(names[i])") } /* Person 1 is called Anna Person 2 is called Alex Person 3 is  called Brain Person 4 is called Jack */Copy the code
for name in names[2...]  { print(name) } /* Brain Jack */ for name in names[...2] { print(name) } /* Anna Alex Brain */Copy the code