I have a preferred methtod for emulating do-while: notdone:=true for notdone { <do something> if <condition> { notdone = false } }
I prefer to use a negative name because I don't see why I should use a unary operator when I can just use the word NOT and not incur any runtime cost. or for !<terminal condition that will evaluate true before> { <do thing that might change terminal condition> } The for is so awesome that the only that is theoretically missing is a do-while. Also, another way to do this would be using labels. If you put a label before the part beginning what you want to repeat, you can put a condition at the end that jumps to the label for your repeat condition. I think the label could even be Do: But it would be pretty cool if a do-while was added, since it won't break old code, but it will break using old versions prior to this addition. It would look like this do { } while <condition> I suppose. Someone posted about a macro processor that probably could do something like this. I personally don't see the point because most of the time I can find a way to use the second construct I showed earlier - a condition that does not evaluate false until the inner block has executed at least once. On Tuesday, 1 May 2018 14:11:04 UTC+3, Hugh Fisher wrote: > > > Another observation from this novice Go programmer: I'm puzzled why > there's no while statement. > > I know it's possible to use a for, but it doesn't feel right to me. I > always > think of for loops as for iterating over data structures. Originally just > arrays, but languages like Python and Objective-C have extended for > loops to other collections as well. "Looping until some condition is met" > for me is a different control structure and needs a different keyword. > > There'd be overlap with the for statement, but if-then-else and switch > with boolean case overlap too. > > And since while has been a reserved keyword in a lot of programming > languages for many decades, I would bet a reasonable amount of > money that a while statement could be added to Go right now and not > break anyone's production code. > > cheers, > Hugh Fisher > > -- 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.