From dd5edce062330ec8d229ebed4a524ce8d5e460c8 Mon Sep 17 00:00:00 2001 From: tsingbx Date: Sat, 11 Nov 2023 07:02:08 +0800 Subject: [PATCH] add doc for assign --- 105-Assignments/assign-1.gop | 10 ++++++++++ 105-Assignments/assign-2.gop | 8 ++++++++ 105-Assignments/assign.gop | 1 - 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 105-Assignments/assign-1.gop create mode 100644 105-Assignments/assign-2.gop delete mode 100644 105-Assignments/assign.gop diff --git a/105-Assignments/assign-1.gop b/105-Assignments/assign-1.gop new file mode 100644 index 0000000..c630b94 --- /dev/null +++ b/105-Assignments/assign-1.gop @@ -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 diff --git a/105-Assignments/assign-2.gop b/105-Assignments/assign-2.gop new file mode 100644 index 0000000..8fc2f14 --- /dev/null +++ b/105-Assignments/assign-2.gop @@ -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 diff --git a/105-Assignments/assign.gop b/105-Assignments/assign.gop deleted file mode 100644 index 8b13789..0000000 --- a/105-Assignments/assign.gop +++ /dev/null @@ -1 +0,0 @@ -