golang / tour

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

tour: does not say if Go has the `else if` construct #559

Open kedarmhaswade opened 6 years ago

kedarmhaswade commented 6 years ago

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

It seems that either this slide, or the If and else slide should make a mention of the else if statement. A first-time reader may get confused by the lack of an explicit mention of else if.

bgadrian commented 6 years ago

What do you mean? From what I know else if is not a construct in languages, you can put anything after an else and it will get executed, including another if.

That being said, I think the Tour should also give idomatic go examples, so this would exclude an if/else/if one, quoting the "Effective Go"

It's therefore possible—and idiomatic—to write an if-else-if-else chain as a switch.

On a second note, maybe we can add the if-else-if... example in the notes of the Switch slide, and state that is recommended to use a switch, or as a code comment.