Created
July 12, 2018 16:11
-
-
Save hi-manshu/2aa2476518ad00f13dd76cca9a29c1f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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