1. If Else statement
Basic syntax
Single condition judgment if condition { //do something}//multi-condition judgment if condition {} else if condition { //do something} else {//do so Mething}
If single condition followed by a statement and then made conditional judgment
If statement;condition{ //do something}//single condition, without the basic judgment of the statement package Mainimport ("FMT") func main () {nu: = 1if nu%2 = = 0 {fmt. Println ("The number is even")} else{fmt. Println ("The number is odd")}}//single condition, with statement of Judgment package Mainimport ("FMT") func main () { if nu: = +; Nu% 2 = = 0 {//with an assignment statement After doing the judging fmt. Println ("The number is even") } else{ fmt. Println ("The number is odd") }}
Note: It is not very build justice to do this because logic looks complicated, but it can reduce the amount of code
If multi-criteria followed by a statement and then made conditional judgment
Multi-condition, without statement of Judgment package Mainimport ("FMT") func main () {num: = 34if num <= 50{fmt. Println ("number is not then")} else if num >= && num <= 100{fmt. Println ("The number is between And1")} else{fmt. Println ("The number is greater than 100")}}//multi-criteria, with Statement of Judgment package Mainimport ("FMT") func main () {//num: = 34if num: = 78;num &L T;= 50{fmt. Println ("number is not then")} else if num >= && num <= 100{fmt. Println ("The number is between And1")} else{fmt. Println ("The number is greater than 100")}}