Re: [go-nuts] Go could really use a while statement

2018-05-13 Thread Janne Snabb
On 2018-05-13 11:34, Hugh Fisher wrote: > I still think a while { ... } loop would be a worthwhile > addition, for the reasons I've already given. Your reason from the original post was: "I know it's possible to use a for, but it doesn't feel right to me." It is not reasonable to demand everyone

Re: [go-nuts] Go could really use a while statement

2018-05-11 Thread Wojciech S. Czarnecki
On Fri, 11 May 2018 13:58:31 +0200 "Wojciech S. Czarnecki" wrote: Errata: of course body is still over condition check in for { body; if !(condition) {break} } construct. https://play.golang.org/p/yHFPIYIpcfp -- You received this message because you are subscribed to the Google Groups "golang

Re: [go-nuts] Go could really use a while statement

2018-05-11 Thread Wojciech S. Czarnecki
On Tue, 1 May 2018 04:11:03 -0700 (PDT) Hugh Fisher wrote: > Another observation from this novice Go programmer: I'm puzzled why > there's no while statement. Because 'for' keeps condition where it belongs (at top); If you want `do..while` as in C, Go offers more readable construct with naked f

Re: [go-nuts] Go could really use a while statement

2018-05-10 Thread Luis Furquim
I think the only real problem here is the lack of do {} while and even this is not a big problem. I think we can happily live with the solution pointed by Sokolov, which is the one I use when needed. But looking at this thread what pops up is that the lacking of this construct at the language

Re: [go-nuts] Go could really use a while statement

2018-05-08 Thread 'Bryan Mills' via golang-nuts
On Thursday, May 3, 2018 at 4:25:34 AM UTC-4, rog wrote: > > FWIW, the thing I miss sometimes is the equivalent of C's: > > while((x = next()) != nil) { > something() > } > > In Go you need to do either: > > for x = next(); x != nil; x = next() { > something()

Re: [go-nuts] Go could really use a while statement

2018-05-03 Thread Louki Sumirniy
yes I made a bunch of errors in my examples... no need for outer scope declaration with initialiser in the initialiser clause (one or the other, you know what I mean) There is a reason why in Go an assignment statement does not also evaluate, but I am not aware of it, and this excludes this fro

Re: [go-nuts] Go could really use a while statement

2018-05-03 Thread Louki Sumirniy
I am writing code in which I pondered exactly using this kind of thing, it involves tree walking on a binary tree, but I decided to scrap this approach because, although you can't see it so clearly in that C code, it's executing a function every loop that probably doesn't need to be. your next(

Re: [go-nuts] Go could really use a while statement

2018-05-03 Thread Sokolov Yura
четверг, 3 мая 2018 г., 11:25:34 UTC+3 пользователь rog написал: > > FWIW, the thing I miss sometimes is the equivalent of C's: > > while((x = next()) != nil) { > something() > } > > In Go you need to do either: > > for x = next(); x != nil; x = next() { > som

Re: [go-nuts] Go could really use a while statement

2018-05-03 Thread roger peppe
FWIW, the thing I miss sometimes is the equivalent of C's: while((x = next()) != nil) { something() } In Go you need to do either: for x = next(); x != nil; x = next() { something() } which duplicates the per-iteration expression, or: for {

Re: [go-nuts] Go could really use a while statement

2018-05-03 Thread Louki Sumirniy
I just think that: for { ... } condition() would be a useful addition to the language because minimum one run of the for block is a common need. Or to avoid any confusion, create a new reserved word: until condition() { ... } The lack of explicit minimum one-run in my opinion runs counter to

Re: [go-nuts] Go could really use a while statement

2018-05-03 Thread Dan Kortschak
Yeah, that's not `for {} else {}`. This is spelled ``` var done bool for condition() { done = true body() } if !done { outOfBody() } ``` On Wed, 2018-05-02 at 22:45 -0700, Sokolov Yura wrote: > >     for { >     Body() >     if !Condition() { >     break >

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Michael Jones
i code that often and comfortably. On Wed, May 2, 2018 at 10:45 PM Sokolov Yura wrote: > > for { > Body() > if !Condition() { > break > } > } > > It is thats simple, guys. > > -- > You received this message because you are subscribed to the Google Grou

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Sokolov Yura
for { Body() if !Condition() { break } } It is thats simple, guys. -- 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 g

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Dan Kortschak
On weird proposals there's also the `for { } else { }` construct that has been put forward before. On Wed, 2018-05-02 at 21:06 +, Michael Jones wrote: > Ok, weird proposal: Make the per-iteration update part of a for loop > change > from "assignment to assignment or boolean expression" to allo

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Michael Jones
but not this... https://play.golang.org/p/cZnSNvi7dNU On Wed, May 2, 2018 at 3:33 PM roger peppe wrote: > On 2 May 2018 at 22:06, Michael Jones wrote: > > Ok, weird proposal: Make the per-iteration update part of a for loop > change > > from "assignment to assignment or boolean expression" to

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread roger peppe
On 2 May 2018 at 22:06, Michael Jones wrote: > Ok, weird proposal: Make the per-iteration update part of a for loop change > from "assignment to assignment or boolean expression" to allow: > > while COND do {...}: > > for i:=0; x[i]<4; {...} > > > do {...} while COND: > > for i:= 0; ; x[i]<4 { ...

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Michael Jones
Ok, weird proposal: Make the per-iteration update part of a for loop change from "assignment to assignment or boolean expression" to allow: *while COND do {...}:* for i:=0; x[i]<4; {...} *do {...} while COND:* for i:= 0; ; x[i]<4 { ...} On Wed, May 2, 2018 at 12:33 PM Louki Sumirniy < louki.

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Louki Sumirniy
It adds absolutely nothing, that's why it should not be accepted. It will lead to a divergence in the way it's used as well. However I think maybe run block once before first condition check would be a useful and powerful addition. Maybe it shows my age that I even know what do-while post-condi

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Ian Lance Taylor
On Wed, May 2, 2018 at 2:48 AM, Hugh Fisher wrote: > > On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor wrote: >> >> >> 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 powe

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread 'Axel Wagner' via golang-nuts
On Wed, May 2, 2018 at 11:48 AM Hugh Fisher wrote: > As for not adding any power, that's why I mentioned if-then-else and > switch. > Switch with boolean cases is the same as if then else. It's not an obscure > side effect either, the Go Tour cheerfully explains how to use it instead > of > if-th

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Louki Sumirniy
for { . } is exactly a while loop. The c style for statement's second clause is exactly this and in c you can do this clumsily with: for (i=1; ; true ) { . } Go assumes that a single boolean expression is the same without initial statement and post block loop statement. If you want to be clev

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Hugh Fisher
On Tuesday, May 1, 2018 at 10:45:30 PM UTC+10, Ian Lance Taylor wrote: > > > 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

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Jan Mercl
On Wed, May 2, 2018 at 11:34 AM Lutz Horn wrote: > You can even write > for true { > } > > to get an infinite loop you will have to break from. for { } works just as well: https://play.golang.org/p/aEkbUjLmf_T -- -j -- You received this message because you are subscribed to the Google Gro

AW: [go-nuts] Go could really use a while statement

2018-05-02 Thread Lutz Horn
> No, I meant a while { ... } loop for foo > 1 { } is exactly what you are looking for. You can even write for true { } to get an infinite loop you will have to break from. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from

Re: [go-nuts] Go could really use a while statement

2018-05-02 Thread Hugh Fisher
On Tuesday, May 1, 2018 at 11:57:13 PM UTC+10, Michael Jones 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. > > No, I meant a whil

Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread Justin Israel
On Wed, May 2, 2018, 1:56 AM Michael Jones 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 t

Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread xiofen77
> > On Tue, May 1, 2018 at 7:36 AM Alisdair > wrote: > >> Isn't `for { ... if cond { break; } }` the same as `do {...} while cond`? >> Whilst having the benefits of not adding new keywords and maintaining the >> logic of the loop entirely within the block of the loop making it simpler >> to u

Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread Alisdair
Isn't `for { ... if cond { break; } }` the same as `do {...} while cond`? Whilst having the benefits of not adding new keywords and maintaining the logic of the loop entirely within the block of the loop making it simpler to understand. On Tue, 1 May 2018 at 14:56, Michael Jones wrote: > Maybe h

Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread Michael Jones
Correct. On Tue, May 1, 2018 at 7:36 AM Alisdair wrote: > Isn't `for { ... if cond { break; } }` the same as `do {...} while cond`? > Whilst having the benefits of not adding new keywords and maintaining the > logic of the loop entirely within the block of the loop making it simpler > to underst

Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread Michael Jones
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. On Tue, May 1, 2018 at 5:45 AM Ian Lance Taylor wrote: > On Tue, May 1, 2018 at 4:11 AM, Hugh Fisher

Re: [go-nuts] Go could really use a while statement

2018-05-01 Thread Ian Lance Taylor
On Tue, May 1, 2018 at 4:11 AM, 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. Orig

[go-nuts] Go could really use a while statement

2018-05-01 Thread Hugh Fisher
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