From f6b8601ed34dbc9e8a3fe654c6a4317650717175 Mon Sep 17 00:00:00 2001 From: tainguyenbp Date: Fri, 31 May 2024 15:15:56 +0700 Subject: [PATCH 1/5] test casting and variable test casting and variable --- hacking-go/learn02/casting/casting.go | 15 +++++++++++++++ hacking-go/learn02/variables/variables.go | 3 +++ hacking-go/learn02/variables/variables02.go | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 hacking-go/learn02/casting/casting.go create mode 100644 hacking-go/learn02/variables/variables02.go diff --git a/hacking-go/learn02/casting/casting.go b/hacking-go/learn02/casting/casting.go new file mode 100644 index 0000000..fc13adb --- /dev/null +++ b/hacking-go/learn02/casting/casting.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" +) + +func main() { + var a, b int = 20, 30 + // Need to convert a and b to float32 before the division + var div float32 = float32(a) / float32(b) + var divs float32 = float32(a/b) + // Cast float32 to int + var divInt = int(div) + fmt.Println(div, divInt, divs) +} diff --git a/hacking-go/learn02/variables/variables.go b/hacking-go/learn02/variables/variables.go index de34469..13341a6 100644 --- a/hacking-go/learn02/variables/variables.go +++ b/hacking-go/learn02/variables/variables.go @@ -16,6 +16,9 @@ func main() { var sampleString_single = "Hello tainguyen" fmt.Println("value variable is: ", a, b, d, f, sampleInt, sampleBoolean, sampleString) + fmt.Println(a, b, d, f, sampleInt, sampleBoolean, sampleString) + fmt.Println("value variable single is: ", sampleInt_single, sampleBoolean_single, sampleString_single) + fmt.Println(sampleInt_single, sampleBoolean_single, sampleString_single) } diff --git a/hacking-go/learn02/variables/variables02.go b/hacking-go/learn02/variables/variables02.go new file mode 100644 index 0000000..5bd6587 --- /dev/null +++ b/hacking-go/learn02/variables/variables02.go @@ -0,0 +1,17 @@ +package main + +import "fmt" + +func main() { + var ( + sampleInt = 500 + sampleBoolean = true + sampleString = "Hello" + ) + + sampleInt1, sampleBoolean1, sampleString1 := 4000, true, "Hello Tai Nguyen" + + fmt.Println(sampleInt, sampleBoolean, sampleString) + fmt.Println(sampleInt1, sampleBoolean1, sampleString1) + +} From 7480f1c15450823edbee590d155aa20f5934bde3 Mon Sep 17 00:00:00 2001 From: tainguyenbp Date: Fri, 31 May 2024 15:42:35 +0700 Subject: [PATCH 2/5] test raw string test raw string --- hacking-go/learn03/constants/constants.go | 20 ++++++++++++ hacking-go/learn03/rawstring/rawstring.go | 38 +++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 hacking-go/learn03/constants/constants.go create mode 100644 hacking-go/learn03/rawstring/rawstring.go diff --git a/hacking-go/learn03/constants/constants.go b/hacking-go/learn03/constants/constants.go new file mode 100644 index 0000000..1979b91 --- /dev/null +++ b/hacking-go/learn03/constants/constants.go @@ -0,0 +1,20 @@ +package main + +import "fmt" + +const Whatever = "whatever" +const helloworld = "Hello World" + +const ( + Const1 = "Constant String" + Int1 = 12345 + True = true +) + +func main() { + fmt.Println(Whatever) + const One = 1 + fmt.Println(One) + fmt.Println(helloworld) + fmt.Println(Const1, Int1, True) +} diff --git a/hacking-go/learn03/rawstring/rawstring.go b/hacking-go/learn03/rawstring/rawstring.go new file mode 100644 index 0000000..d3d7052 --- /dev/null +++ b/hacking-go/learn03/rawstring/rawstring.go @@ -0,0 +1,38 @@ +package main + +import "fmt" + +func main() { + rawstr := + `First line +some new lines +more new lines +"double quotes" +` + fmt.Print(rawstr) + + rawstr1 := + `one line +two line +three line +"fours line" +` + + fmt.Print(rawstr1) + + rawstr2 := + `Line with tab here +Line with newline +and more lines +` + + fmt.Print(rawstr2) + + rawstr3 := + `This is a raw string with backticks: + It spans multiple lines and includes "quotes" and \backslashes\. +` + + fmt.Print(rawstr3) + +} From 2f96e986a7a0a55e28c4f1637f4171c19023db37 Mon Sep 17 00:00:00 2001 From: tainguyenbp Date: Fri, 31 May 2024 16:47:45 +0700 Subject: [PATCH 3/5] tesst for loop tesst for loop --- hacking-go/learn04/for/forloop1.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 hacking-go/learn04/for/forloop1.go diff --git a/hacking-go/learn04/for/forloop1.go b/hacking-go/learn04/for/forloop1.go new file mode 100644 index 0000000..cff3bfa --- /dev/null +++ b/hacking-go/learn04/for/forloop1.go @@ -0,0 +1,30 @@ +package main + +import "fmt" + +func main() { + + // var sum int + sum := 0 + for i := 0; i < 10; i++ { + sum += i + } + fmt.Println(sum) + + // // var sum int + sum1, i1 := 0, 0 + for i1 < 30 { + sum1 += i1 + i1++ + } + + fmt.Println(sum1) + + // // var sum int + sum2 := 1 + for i2 := 0; i2 < 40; i2++ { + sum2 += i2 + } + fmt.Println(sum2) + +} From 73bd5ed75cfcf51e0bbdf6cab3af2692c1134b97 Mon Sep 17 00:00:00 2001 From: tainguyenbp Date: Fri, 31 May 2024 17:20:55 +0700 Subject: [PATCH 4/5] test if test if --- hacking-go/learn04/for/incdec.go | 13 +++++++++++++ hacking-go/learn04/if/if.go | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 hacking-go/learn04/for/incdec.go create mode 100644 hacking-go/learn04/if/if.go diff --git a/hacking-go/learn04/for/incdec.go b/hacking-go/learn04/for/incdec.go new file mode 100644 index 0000000..183f8a1 --- /dev/null +++ b/hacking-go/learn04/for/incdec.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +func main() { + + // var sum int + sum, i := 0, 0 + // This will not work + sum = i++ + + fmt.Println(sum) +} diff --git a/hacking-go/learn04/if/if.go b/hacking-go/learn04/if/if.go new file mode 100644 index 0000000..106a453 --- /dev/null +++ b/hacking-go/learn04/if/if.go @@ -0,0 +1,19 @@ +package main + +import "fmt" + +func main() { + a := 20 + b := 20 + + if b > a { + + fmt.Println(b, ">", a) + } + if b < a { + fmt.Println(b, "<", a) + } + if b == a { + fmt.Println(b, "=", a) + } +} From 658a317002cfae5a39c5b69b42d895403e9ebfe7 Mon Sep 17 00:00:00 2001 From: tainguyenbp Date: Fri, 31 May 2024 17:33:43 +0700 Subject: [PATCH 5/5] test if else test if else --- hacking-go/learn04/if/if2.go | 11 +++++++++++ hacking-go/learn04/if/ifelse.go | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 hacking-go/learn04/if/if2.go create mode 100644 hacking-go/learn04/if/ifelse.go diff --git a/hacking-go/learn04/if/if2.go b/hacking-go/learn04/if/if2.go new file mode 100644 index 0000000..5f76221 --- /dev/null +++ b/hacking-go/learn04/if/if2.go @@ -0,0 +1,11 @@ +package main + +import "fmt" + +func main() { + if var1 := 100; var1 > 20 { + fmt.Println("Value inside if:", var1) + } + // Cannot use the variable var1 here + +} diff --git a/hacking-go/learn04/if/ifelse.go b/hacking-go/learn04/if/ifelse.go new file mode 100644 index 0000000..a0fb799 --- /dev/null +++ b/hacking-go/learn04/if/ifelse.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +func main() { + if var1 := 10; var1 > 20 { + fmt.Println("Value inside if:", var1) + } else { + // Can use var1 here + fmt.Println("Value inside else:", var1) + } + +}