Another mistake in the Go Language programming book

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

"Go language Programming" in the book "2.4.1 Conditional statement" There is a mistake, should be in the book using the Go language version is less than the 1.1 version, the original text as follows:

In a function that has a return value, it is not allowed to "final"ReturnStatement is contained in theIf...else ...Structure,
Otherwise, the compilation will fail:
function ends without areturnStatement。
The reason for the failure is thatGoThe compiler could not find the end of the functionReturnStatement. The following are examples of failed compilations:
funcExample (xint) int     If x = = 0 {
        return 5
else {
x
   }

The 1.1 go language and later versions already support the IF else conditional statement to return the returned value directly.

I am working with the latest stable version of 1.3.3 to compile and run the snippet.

This article is from the "Pine" blog, be sure to keep this source http://dongsong.blog.51cto.com/916653/1587809

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.