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()
> }
>
> which duplicates the per-iteration expression, or:
>
> for {
> x = next()
> if x == nil {
> break
> }
> something()
> }
>
> which is 4 lines longer and the invariant is inverted.
>
> A two-part for statement could potentially do that:
>
> for x = next; x != nil {
> something()
> }
>
> but it's too subtly different from the normal form to be a good language
> change.
>
Funny you should mention that, because I proposed a very similar change
back in March!
(https://golang.org/issue/24282)
It's almost certainly too invasive a change on its own, but if we happen to
decide that a breaking change is the best way to address
https://golang.org/issue/20733, I'm hopeful that it will at least be
considered.
On 3 May 2018 at 08:18, Dan Kortschak <[email protected]
> <javascript:>> wrote:
> > 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
> >> }
> >> }
> >>
> >> 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 [email protected] <javascript:>.
> > 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 [email protected].
For more options, visit https://groups.google.com/d/optout.