Can someone walk me through how this For Loop in the Golang tour equals 45?

Written by
Link to Post

https://www.reddit.com/r/golang/comments/bz0zlf/can_someone_walk_me_through_how_this_for_loop_in/ by 

package main

import “fmt”

func main() {

sum := 0 for i := 0; i < 10; i++ { sum += i } fmt.Println(sum) 

}

output:

45

Program exited.

—- I feel stupid I don’t understand this. i++ adds 1 each time it loops, correct?

submitted by /u/HeavierMetal89
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply