var action: String
var person = "hater"
if person == "hater" {
action = "hate"
} else if person == "player" {
action = "play"
} else {
action = "cruise"
}
// check whether a number is positive, negative, or 0.
let number = 0
if (number > 0) {
print("Number is positive.")
}
else if (number < 0) {
print("Number is negative")
}
else {
print("Number is 0.")
}
print("This statement is always executed")
let number = 10
// check if number is greater than 0
if (number > 0) {
print("Number is positive.")
}
print("The if statement is easy")
if (condition) {
// body of if statement
}
if (condition) {
// block of code if condition is true
}
else {
// block of code if condition is false
}
var someValue:Int?
var someAnotherValue:Int! = 0
if someValue != nil {
print("It has some value (someValue!)")
} else {
print("doesn't contain value")
}
if someAnotherValue != nil {
print("It has some value (someAnotherValue!)")
} else {
print("doesn't contain value")
}
let number = 10
if (number > 0) {
print("Number is positive.")
}
else {
print("Number is negative.")
}
print("This statement is always executed.")