Questions And Answers

More Tutorials

Go If..else..else if

In Go you can have an If statement without an else. A statement can precede conditionals; any variables declared in this statement are available in all branches. Parentheses are not required for writing a condition in an If statement.

Example of If..Else..Else If in Go

package main

import "fmt"

func main() {

// condition without parenthesis + else
    if 9%2 == 0 {
        fmt.Println("9 is even")
    } else {
        fmt.Println("9 is odd")

// condition wuth if statement only
    if 16%4 == 0 {
        fmt.Println("16 is divisible by 4")

// multiple conditions
    if num := 9; num < 0 {
        fmt.Println(num, "is negative")
    } else if num < 10 {
        fmt.Println(num, "has 1 digit")
    } else {
        fmt.Println(num, "has multiple digits")


In this page (written and validated by ) you learned about Go If..else..else if . What's Next? If you are interested in completing Go tutorial, your next topic will be learning about: Go Switch.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.