Here's an example of creating an if statement with an else if in Go:
main.go279 chars16 lines
In this code, we declare a variable num
with a value of 10
. We then create an if statement that checks if num
is greater than 20
. If it is, the program prints "Number is greater than 20".
If num
is not greater than 20
, the program then checks if num
is greater than 15
using an else if statement. If num
is between 16 and 20, the program prints "Number is between 16 and 20".
Finally, if neither of the previous conditions are true, the program executes the else statement and prints "Number is less than or equal to 15".
gistlibby LogSnag