8000 Added for loop, conditionals, control flow statements tutorials · anarchymonkey/learn_golang@ef57513 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef57513

Browse files
committed
Added for loop, conditionals, control flow statements tutorials
1 parent 5444986 commit ef57513

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import "fmt"
4+
5+
// We will learn about defer, panic, recover
6+
7+
func calcSum[K int | float64](a K, b K) K {
8+
return a + b
9+
}
10+
11+
func deferFuncExample() {
12+
// defer stalls the execution of the instance linked to it
13+
// defer runs after the corrosponding function block has finished running
14+
// multiple defers use the LIFO algo, last defer goes out first
15+
defer fmt.Println("Something has been calculated")
16+
sum := calcSum(1, 2)
17+
fmt.Println("The sum is", sum)
18+
19+
defer fmt.Println("The sum of floats has been calculated")
20+
21+
fmt.Println(calcSum(1.100, 2.200))
22+
}
23+
24+
func panicFuncExample() {
25+
26+
}
27+
28+
func main() {
29+
deferFuncExample()
30+
}

go_basics/defer_panic_recover/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module anarchymonkey.com/go-basics/defer-panic-recover
2+
3+
go 1.20

0 commit comments

Comments
 (0)
0