"Some grammatical foundations of 001:go language"

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

1. Looping statements

Go is only for a loop statement keyword, but supports 3 forms of initialization and stepping expressions can be multiple value conditional statements Each loop is re-examined, so it is not recommended to use a function in a conditional statement, try to calculate the condition in advance and replace the opening brace with a variable or constant with the conditional statement on the same line

1.1 For Infinite loops

1  for {2      // Break ; 3     // equivalent     while 4 }

1.2 for with conditional expressions

1 if 3 {2// operation a3 }

1.3 for Classic style

1  for 0 3; i++{2//code3 }

1.2 Switch Selection

You can use any type or expression as a conditional statement without writing a break, and once the condition conforms to auto-terminate, if you want to continue with the next case, you need to use the Fallthrough statement to support an initialization expression (which can be parallel), and the right side must be the same line as the semicolon opening brace and the conditional statement.

 

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.