if swift code example
Example 1: swiftui if use
if expression {
}
Example 2: if statement swfit
var a: Int = 3
if a == 3 {
print("Hello World")
} else if a < 3 {
print("dlroW olleH")
} else {
print("42")
}
Example 3: swift if statement
let num = 15
var result = ""
if (num > 0) {
result = "Positive Number"
}
else {
result = "Negative Number"
}
print(result)
Example 4: swift 5 if statement
let a = -5
a >= 0 ? doThis(): doThat()
func doThis() {
println("Do This")
}
func doThat() {
println("Do That")
}