On Tue, May 1, 2018 at 4:11 AM, Hugh Fisher <hugo.fis...@gmail.com> 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.
A `while` statement would presumably be exactly identical to a `for` statement with a single condition. So adding a `while` statement would not add any power to the language, and would add an additional keyword. All language choices are a cost benefit decision. In this case the benefit is a looping construct that some people will find clearer to read and write, and the cost is a new keyword that everybody needs to learn, and that at this point in the language's evolution will likely break some, even if not much, existing code. I don't think the benefit is worth the cost. Ian -- 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.