Created
April 10, 2017 23:54
-
-
Save shivakar/d0dd1adbd68bfcbcd2f540453a16ee68 to your computer and use it in GitHub Desktop.
Updating variables using older values of the variables
This file contains 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
import "fmt" | |
func printVariables(message string, a, b, c int64) { | |
fmt.Println(message) | |
fmt.Println("a = ", a) | |
fmt.Println("b = ", b) | |
fmt.Println("c = ", c) | |
fmt.Println("") | |
} | |
func main() { | |
var a, b, c int64 | |
a, b, c = 10, 20, 30 | |
printVariables("Initial conditions: ", a, b, c) | |
a = a + b + c | |
b = a + b + c | |
c = a + b + c | |
printVariables("After running a=a+b+c, b=a+b+c, c=a+b+c using 3 statements: ", a, b, c) | |
a, b, c = 10, 20, 30 | |
printVariables("After reset: ", a, b, c) | |
a, b, c = a+b+c, a+b+c, a+b+c | |
printVariables("After running a=a+b+c, b=a+b+c, c=a+b+c using one assign statement: ", a, b, c) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment