Skip to content

Instantly share code, notes, and snippets.

@hi-manshu
Created July 12, 2018 16:11
Show Gist options
  • Save hi-manshu/2aa2476518ad00f13dd76cca9a29c1f7 to your computer and use it in GitHub Desktop.
Save hi-manshu/2aa2476518ad00f13dd76cca9a29c1f7 to your computer and use it in GitHub Desktop.
package main
//imported the package fmt
import "fmt"
//main function gets called when the program runs
func main() {
//declared a variable with initial value = 0
sum := 0
//for loop initialization, with index<5 and incremented by one at a time using index ++
for index := 0; index < 5; index++ {
//add the value of index in sum
sum += index
}
//print the value of sum
fmt.Println("sum =", sum)
}
>>go run forExample.go
>>sum = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment