Skip to content

Commit

Permalink
Merge pull request #60 from tsingbx/assign
Browse files Browse the repository at this point in the history
add doc for assign
  • Loading branch information
xushiwei authored Nov 10, 2023
2 parents 9c77169 + dd5edce commit 14eeb4e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions 105-Assignments/assign-1.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# assignment
// = is used for assigning. The values of multiple variables can be changed in one line. In this way, their values can be swapped without an intermediary variable.
var age int

age = 21 // = is used for assigning.
println age

var a, b int = 0, 1
a, b = b, a // The values of multiple variables can be changed in one line.
println a, b // 1, 0
8 changes: 8 additions & 0 deletions 105-Assignments/assign-2.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# = vs :=
// := is used for declaring and initializing. Multiple variables can be declared and intialized at one line.
age := 21 // age is declared and initialized to 21
println age

a, b := 0, 1 // multiple variables can be declared and intialized at one line.
a, b = b, a
println a, b // 1, 0
1 change: 0 additions & 1 deletion 105-Assignments/assign.gop

This file was deleted.

0 comments on commit 14eeb4e

Please sign in to comment.