print a, aa, aaa



package main
import (
    "fmt"
    "time"
)
func main() {
    s := "a"
    for ; s != "aaaaa"; {
        fmt.Println(s)
        s = s + "a"
        time.Sleep(1000 * time.Millisecond)
    }
}

Prints...
a
aa
aaa
aaaa

Here's a different way of doing this that I found on stackoverflow...
package main
import (
    "fmt"
    "bytes"
)
func main() {
    var buffer bytes.Buffer
    for i := 0; i < 10; i++{
        buffer.WriteString("a")
        fmt.Println(buffer.String())
    }
}

No comments:

Post a Comment