golang / tour

[mirror] A Tour of Go
BSD 3-Clause "New" or "Revised" License
1.54k stars 521 forks source link

tour: if vs for info text #743

Open wn2owg opened 5 years ago

wn2owg commented 5 years ago

Context: https://tour.golang.org/flowcontrol/5

on 5/14 of if, text says parens are NEED NOT. sure enough if (x>1) or if x>1 both work which IS what the text implies

so on for 1/14 the text IMPIES no parens but cutely braces required, so for fun tried them like the if

for (i:=1; i<10;i+1 ) but this FAILS with syntax error.

I was surprised because of "if" behavior, but also the texts implication.

Bill

ALTree commented 5 years ago

Interesting observation. I think you're right. If I read

Go's if statements are like its for loops; the expression need not be surrounded by parentheses ( )

I would deduce that "the expression need not be surrounded by parentheses" also holds for for loops, but "need not" is misleading in that case since you cannot use ( ) in the loop condition.

Abby3017 commented 4 years ago

Should I send a PR with a fix like this

the if expression need not be surrounded by parentheses ( ) but the braces { } are required.

It won't be misleading and can provide clear and concise statement.