In programming When The flow chart is as follows: Use The result of the above code execution is: if statement, you can use the optional else statement, else expression in the statement is the Boolean expression false when it is executed. 2.19.1. Grammar #
Go language the syntax of the if...else statement is as follows:If Boolean expression {
/* Execute when Boolean expression is true */
} else {
/* Execute when Boolean expression is false */
}
If is in a Boolean expression of true , the block of statements immediately following the execution of the false then execute `` else``sentence block.
2.19.2. Example #
if else to judge the size of a number:Example #
package main
import "fmt"
func main() {
/* Definition of Local Variables */
var a int = 100;
/* Judging Boolean Expressions */
if a < 20 {
/* If the condition is true, execute the following statement */
fmt.Printf("A less than 20\\n" );
} else {
/* If the condition is false, execute the following statement */
fmt.Printf("A not less than 20\\n" );
}
fmt.Printf("The value of a is: %d\\n", a);
}
A not less than 20
The value of a is: 100