Use else if when you need to check several conditions in order.
Go evaluates the chain from top to bottom and runs only the first matching branch:
grade := 8
if grade < 5 {
fmt.Println("Failed the test")
} else if grade <= 7 {
fmt.Println("Passed the test")
} else if grade <= 9 {
fmt.Println("Good Job")
} else {
fmt.Println("Perfect")
}
Assignment
Use an if / else if / else chain to print the message for grade.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
