The syntax of the When The flow chart is as follows: Use The result of the above code execution is:
if
statement consists of a Boolean expression followed by one or more statements. 2.18.1. Grammar #
if
statement in
Go
programming language is as follows:If Boolean expression {
/* Execute when Boolean expression is true */
}
If
is in a Boolean expression of
true
, the statement block immediately following is executed, and if it is
false
, it is not executed.
2.18.2. Example #
if
to determine the size of a numeric variable:Example #
package main
import "fmt"
func main() {
/* Define local variables */
var a int = 10
/* Using an if statement to determine a Boolean expression */
if a < 20 {
/* If the condition is true, execute the following statement */
fmt.Printf("A less than 20\\n" )
}
fmt.Printf("The value of a is : %d\\n", a)
}
A less than 20
The value of a is: 10