Three ways to if,swich,for the Go language

Source: Internet
Author: User
Tags define local

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.