I'm doing an exercise on Go that asks me to print a letter like this
G
GG
GGG
GGGG
GGGGG
for 25 different lines, and adding one more letter each time.
I'm asked to solve it one time using only one for loop, and then again but with two for loops. I already solved both, but even though my code using two for loops works gives the right output, I think it's weird and not ok:
func manyG2() {
var counter string
for i := 0; i <= 24; i++ {
for x := 0; x == 0; x++ {
counter += "G"
fmt.Println(counter)
}
}
}
How other way can I write it with two for loops?
Here is the another way to do it, instead of concatenating every time to the string ...
func manyG2() {
for i := 0; i < 25; i++ {
for j := 0; j <= i; j++ { // num of Gs are equal to the row no.
fmt.Print("G")
}
fmt.Println()
}
}