Example:
If a < 5 { return 0} else { return 1}
For conditional statements, the following points need to be noted:
? Conditional statements do not need parentheses to enclose conditions ();
? The curly braces {} must exist regardless of the statement body.
? The left curly brace {must be in the same row as if or else;
? After the IF, the conditional statement can be added before the variable initialization statement, use; interval;
? In a function that has a return value, the "final" return statement is not allowed to be included in the If...else ... Structure, otherwise the compilation fails:
The reason for the failure is that the go compiler cannot find the return statement that terminates the function. The following are examples of failed compilations:
func example (x int) int {if x = = 0 {return 5} else {return x}}
Go language conditional statement if else