Go language learning loops in 3:go language

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

There is only one loop statement in the go language, which is for:


Here is the first explanation: the Role of =:

: = When the type of the operand on the right is determined, it can be used to do the assignment: = can only be placed inside the function.

of basic for loops do not have to be ' (') ' (or even force them to use them), they look like C or Java, and ' {} ' is required.

Look at one of the following programs:

  Hello project main.go 
Package Main
Import"FMT"
FuncMain (){
 sum: =1
  forsum<
 sum+= sum
    }
 FMT. PRINTLN (SUM)
}
As in C or Java, you can leave the front and back statements empty

Since there is only a for in go to use as a loop, how can our while (i<n) and while (True) be implemented? Take a look at the following program:

Package Main
Import"FMT"
FuncMain (){
 sum: =1
  forsum<
 sum+= sum
    }
 FMT. PRINTLN (SUM)
}
This is the notation of while (i<n)

Package Main
FuncMain (){
  for{
    }
}
This is the notation for the dead loop, with no variables behind for

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.