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.


On 3 May 2018 at 08:18, Dan Kortschak <dan.kortsc...@adelaide.edu.au> 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 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.

Reply via email to