ib := truefor i := a.X; i != b.X || ib; i = i + b.X - a.X {ib = false//stuff}
for i := a.X;; i = i + b.X - a.X {//stuff
It is a significant frustration for me, actually.
What I do is to leave out the test completely at the top and put it at the bottom , Just as you show. Comes up often in linked-list traversal and math code.
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Oct 7, 2016, at 7:55 PM, Michael Jones <michae...@gmail.com> wrote:It is a significant frustration for me, actually.
What I do is to leave out the test completely at the top and put it at the bottom , Just as you show. Comes up often in linked-list traversal and math code.
i := aloop1: //stuff//..fmt.Println(i, a, b)//stuffif i != b {i = i + b - agoto loop1}
In this code you could use empty blocks, e.g.:{i := 0loop:fmt.Println(i)if i < 10 {i++goto loop}}or:i := 0{loop:fmt.Println(i)if i < 10 {i++goto loop}}or:i := 0loop:{fmt.Println(i)if i < 10 {i++goto loop}}
repeat i := a.X {
repeat j := a.Y {
repeat k := a.Z {
//fmt.Println(" xyz ", i, j, k)
} until k == b.Z; k = k + b.Z - a.Z
} until j == b.Y; j = j + b.Y - a.Y
} until i == b.X; i = i + b.X - a.X
I prefer to show the intent of the bool with something like
for done :=false;!done;{
//stuff
done = xxx // done = expr in until(expr)
}