Here is an example of an if statement with an else if and else with a condition in Go:
main.go255 chars16 lines
In this code, we have a variable called num
that has a value of 10
. We use an if statement with an else if and else to check the value of num
. The condition for the first if statement is num < 5
. If this condition is true, the code prints "Number is less than 5". If the condition is false, the code moves on to the else if statement.
The condition for the else if statement is num >= 5 && num < 10
. If this condition is true, the code prints "Number is between 5 and 10". If the condition is false, the code moves on to the else statement.
The else statement doesn't have a condition, so it will execute if all of the previous conditions are false. In this case, it prints "Number is greater than or equal to 10".
gistlibby LogSnag