Skip to content

Commit

Permalink
Merge pull request #6 from tainguyenbp/feat/learning-hacking-with-gol…
Browse files Browse the repository at this point in the history
…ang02

learning hacking with golang
  • Loading branch information
tainguyenbp authored Jun 3, 2024
2 parents eddca28 + 658a317 commit 80ad865
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hacking-go/learn02/casting/casting.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions hacking-go/learn02/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
17 changes: 17 additions & 0 deletions hacking-go/learn02/variables/variables02.go
Original file line number Diff line number Diff line change
@@ -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)

}
20 changes: 20 additions & 0 deletions hacking-go/learn03/constants/constants.go
Original file line number Diff line number Diff line change
@@ -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)
}
38 changes: 38 additions & 0 deletions hacking-go/learn03/rawstring/rawstring.go
Original file line number Diff line number Diff line change
@@ -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)

}
30 changes: 30 additions & 0 deletions hacking-go/learn04/for/forloop1.go
Original file line number Diff line number Diff line change
@@ -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)

}
13 changes: 13 additions & 0 deletions hacking-go/learn04/for/incdec.go
Original file line number Diff line number Diff line change
@@ -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)
}
19 changes: 19 additions & 0 deletions hacking-go/learn04/if/if.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
11 changes: 11 additions & 0 deletions hacking-go/learn04/if/if2.go
Original file line number Diff line number Diff line change
@@ -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

}
13 changes: 13 additions & 0 deletions hacking-go/learn04/if/ifelse.go
Original file line number Diff line number Diff line change
@@ -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)
}

}

0 comments on commit 80ad865

Please sign in to comment.