On Wed, May 2, 2018, 1:56 AM Michael Jones <michael.jo...@gmail.com> wrote:
> Maybe he meant "until" aka "do {...} while cond" -- this is a valuable and > missing mechanism. The argument back in the day was that having just one > looping construct was more friendly to tooling. > Based on this... > 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. ... I didn't think it meant a different construct like 'do while'. It just comes down to how one thinks of for loops. To me, even though I come from a Python background with a 'while' construct, I don't think of a for loop in Go as specifically iterating over data structures. I think of it as looping for the duration of a True condition. So that being said I could see this being the same: while item := range items {...} > On Tue, May 1, 2018 at 5:45 AM Ian Lance Taylor <i...@golang.org> wrote: > >> 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. >> > > > -- > Michael T. Jones > michael.jo...@gmail.com > > -- > 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. > -- 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.