-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tainguyenbp/feat/learning-hacking-with-gol…
…ang02 learning hacking with golang
- Loading branch information
Showing
10 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |