A go language for loop has 3 forms, only one of which uses semicolons.
Package Main
InPort
"FMT"
)
FNNC Main () {
For i:=0;i<5;i++{
Fmt.println ("%d,i")
}
}
Dead loop
Func Main () {
for {
Fmt.println ("Dead Loop")
}
}
Add a loop
Func Main () {
I:=5
For i>0{
I=i-1
Fmt.println ("%d,i")
}
}
The switch of Go is very flexible. An expression does not have to be a constant or an integer.
Func main (a int) {
Digital Switch A {case 1: FMT. Println ("1")
Case 2: FMT. Println ("2") Case 3: FMT. Println ("3") }}
If statement
If x > 0 { return y} else { return x}
If Boolean expression 1{/* executes when Boolean expression 1 is true */if Boolean expression 2 {/* isexecuted when Boolean expression 2 is true */}
}
Nested Else If...else statements in an if statement
PackageMainImport "FMT"Func Main() { /* Define Local Variables */ VarAInt = 100 VarBInt = 200 /* Judging condition */ IfA== 100 { /* If condition statement is true */ IfB== 200 { /* if condition statement true execution * / Fmt. Printf ( } } Fmt.printf ( "a value:%d\n" , a Fmt. Printf ( "B value:%d\n" , b ) ; } /span>
Three ways to if,swich,for the Go language