Skip to content

Instantly share code, notes, and snippets.

@shivakar
Created April 10, 2017 23:54
Show Gist options
  • Save shivakar/d0dd1adbd68bfcbcd2f540453a16ee68 to your computer and use it in GitHub Desktop.
Save shivakar/d0dd1adbd68bfcbcd2f540453a16ee68 to your computer and use it in GitHub Desktop.
Updating variables using older values of the variables
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