-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.go
103 lines (74 loc) · 1.46 KB
/
function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import "fmt"
// func method without paramater
func nama(){
fmt.Println("herdo dimas pratirto")
}
//example function with parameter
func namaumur(nama string, umur int){
fmt.Println("nama saya ",nama, " dan umur saya ", umur)
}
//example return values
func penjumlahan(angka1 int, angka2 int) int {
return angka1 + angka2
}
//example named return values
func perkalian(angka1 int, angka2 int)(hasil int){
hasil = angka1 * angka2
return
}
//example for multiple return values
func kalijumlah(angka1 int, angka2 int)(hasil int, result string){
hasil = angka1 + angka2
result = "ini adalah hasil "
return
}
//example for recursion
func testcount(x int) int {
if x == 11 {
return 0
}
fmt.Println(x)
return testcount(x + 1)
}
//example 2 for recursion
func count(i int)int{
if i == 10{
return 0
}
fmt.Println(i)
return count(i + 1)
}
func main(){
/*
example multiple call function
for x:=0; x<10; x++{
nama()
}
*/
/*
example for function with parameter
namaumur("herdo", 30)
*/
/*
example for return values
fmt.Println(penjumlahan(10,10))
*/
/*example for name return values
total := perkalian(20,20)
fmt.Println(total)
*/
/*
example for multiple return
cetak, hasil := kalijumlah(10,10)
fmt.Println(cetak, hasil)
*/
/*
example 1 for recursion
testcount(1)
*/
/*
example 2 for recursion
count(1)
*/
}