Open valaparthvi opened 6 years ago
Hi, Above behavior is expected one. "else" statement should be in same line as the closing brace of corresponding "if". Similarly, opening brace of if should be in same line as "if". Otherwise running such code should generate the error. However, opening brace of else can be in the new line. Its always good idea to run go fmt on the code before running the code to format the code as per the go standards and to catch any possible syntax errors. BR.
I understand that it's the expected behavior. But what I meant was, it would be helpful if that was mentioned in the tutorial.
Thanks for the report.
In general, I think that slide could use a little more text. It's the one that introduces the else
block and it says almost nothing about it.
Newb trying Hacktoberfest, tiny change but appreciate pointers nonetheless!
bagaimana cara agar output sesuai ketentuan dalam README
Context: https://tour.golang.org/flowcontrol/7 The "}" closing brace of
if
statement must be immediately followed by anelse
statement if any. Writingelse
on a separate line(like we do in Python, C, Java, etc) will generate aSyntaxError
in Go. Example:Output: prog.go:12:2: syntax error: unexpected else, expecting }