WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - if statement


An if statement consists of a Boolean expression followed by one or more statements.

Syntax

The syntax of the if statement in the Go programming language is as follows:

if Boolean expression {
    /* Execute when the Boolean expression is true */
}

If when the Boolean expression is true, the block immediately followed is executed, and if it is false, it is not executed.

The flow chart is as follows:

Instance

Use if to determine the size of a variable:

Instance

package main

import "fmt"

func main() {
   /* Defining local variables */
   var a int = 10
 
   /* Use the if statement to determine the boolean expression */
   if a < 20 {
       /* If the condition is true then execute the following statement */
       fmt.Printf("a Less than 20\n" )
   }
   fmt.Printf("a Value : %d\n", a)
}

The above code execution result is:

a less 20
a value is  : 10