create an if statement with an else if and else with a condition in go

Here is an example of an if statement with an else if and else with a condition in Go:

main.go
package main

import "fmt"

func main() {
	num := 10

	if num < 5 {
		fmt.Println("Number is less than 5")
	} else if num >= 5 && num < 10 {
		fmt.Println("Number is between 5 and 10")
	} else {
		fmt.Println("Number is greater than or equal to 10")
	}
}
255 chars
16 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