I've been set a challenge that I'm trying to get my head around, but am struggling with the best (or 'correct') way to implement it. The challenge is to create a simple console app written in Go that calculates the sum of squares of n numbers. However, I must do so without using a for
loop and only the standard library.
Having never touched Go before this point, I assumed it would just be a case of using a while
loop, yet after digging through the docs I know that functionality in Go is folded into the for
statement. No luck there then.
I also know that Go implements goto
statements which seem would be an option but in my ~2 years of programming, I've been taught to avoid them like the plague as they're 'terrible form' and only hang around for a few specific cases, thus I cannot imagine that this challenge is looking for me to come up with a goto
statement.
While I know that Go has some more complex flow control functionality that I haven't mentioned, I haven't come across anything obvious that would replicate the functionality that I'd get from a simple for
loop.
What conceptually can replicate a for
loop in go?
for
because I don't want to" it's usually a very uninteresting problem 3) the alternative solution is a trivial "use recursion" and nothing else. But personally I don't see the need to downvote this, just post the (admittedly trivial and uninteresting) answer then move on.