golang / tour

[mirror] A Tour of Go
BSD 3-Clause "New" or "Revised" License
1.55k stars 519 forks source link

tour:explanation for "For is Go's "while"" is not enough! #785

Open Mehdi-orang opened 5 years ago

Mehdi-orang commented 5 years ago

I don't know below code how computing the out!! https://tour.golang.org/flowcontrol/3

package main

import "fmt"

func main() { sum := 1 for sum < 9 { sum += sum } fmt.Println(sum) }

ghost commented 5 years ago

Try something like this?

 package main

 import "fmt"

 func main() {
    sum := 1
    for sum < 9 {
+       fmt.Println(sum)
        sum += sum
    }
    fmt.Println(sum)
 }