for <condition> { . }

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; <condition>; true ) { . }

Go assumes that a single boolean expression is the same without initial 
statement and post block loop statement. If you want to be clever it is even 
possible to use multiple assignment operations to iterate one thing and perform 
an action on a separate thing:

fibo := 0
for i := 0; i<11 ; i, fibo = i + 1, fibo + i {}

which would produce the tenth element of the fibonacci series.

The only loop construct not possible with Go's for is the first condition to be 
evaluated after the first execution of the block.

As someone pointed out, for this the most concise construction is:

for {
  ...
  if condition {
    break
  }
}

or maybe this would work:

for cond := true; cond; {
  ...
  if <condition> {
    cond = false
  }
}

but I think the first is less wordy.

If there was a language change for this, putting an optional condition after an 
unconditional for would probably break no code, eg:

for {
  ...
} <condition>

assuming this condition is evaluated in the for block scope

-- 
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