On Friday, August 4, 2017 at 6:59:41 PM UTC-4, Doğan Kurt wrote: > > Fallthrough must be a design choice but goto's restriction is a necessity. > > What happens if you jump into the middle of an if block? You skipped the > condition check, you run the code after the goto label, what about the code > before the label, there might be some variables initialized, and how will > you use this variables if you skip the initialization code. >
> Same applies to loops, furthermore, which iteration are you gonna be in? > Compiler can detect whether or not some undeclared variables will be used package main func main() { goto L // error: goto L jumps over declaration of i var i int _ = i L: println("not use i any more") } > > On Saturday, August 5, 2017 at 12:48:40 AM UTC+2, T L wrote: >> >> >> >> On Tuesday, August 1, 2017 at 8:41:21 AM UTC-4, Jan Mercl wrote: >>> >>> On Tue, Aug 1, 2017 at 2:34 PM Fumi Takeuchi <fmodqu...@gmail.com> >>> wrote: >>> >>> > Example code: https://play.golang.org/p/dVtPVt3oKt >>> > >>> > Maybe `fallthrough` statement cannot be used in `if` block even if >>> it's put inside `swicth` block) >>> >>> True: It may be used only as the final non-empty statement in such a >>> clause <https://golang.org/ref/spec#Fallthrough_statements>. >>> >> >> why to make this restriction? >> >> And why to make the similar restriction for goto: >> >> https://golang.org/ref/spec#Goto_statements >> "A "goto" statement outside a block cannot jump to a label inside that >> block" >> >> >> >>> >>> > 3. Other (please comment) >>> >>> https://play.golang.org/p/8rL0zqaLP3 >>> >>> -- >>> >>> -j >>> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.