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