Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5674bba

Browse files
committed
first commit
0 parents commit 5674bba

19 files changed

+373
-0
lines changed

‎.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
out
2+
node_modules
3+
.vscode-test
4+
.DS_Store

‎Array.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
var nums [10]int
7+
8+
for i := 0; i < 10; i++ {
9+
nums[i] = i + 1
10+
}
11+
PrintValue(nums[:])
12+
13+
}
14+
func PrintValue(arr []int) {
15+
for i := 0; i < len(arr); i++ {
16+
fmt.Println(arr[i], " ")
17+
}
18+
}

‎DecisionMaking.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
x := 10
7+
if x != 10 {
8+
fmt.Println("X is not equal to 10")
9+
} else if x == 10 {
10+
fmt.Println("X is equal to 10")
11+
}
12+
}
4.28 MB
Binary file not shown.

‎ErrorHandling.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
)
7+
8+
func main() {
9+
height := 5
10+
width := 5
11+
res, err := getAreaOfARectangle(height, width)
12+
13+
if err != nil {
14+
fmt.Println(err)
15+
} else {
16+
fmt.Println(res)
17+
}
18+
19+
}
20+
func getAreaOfARectangle(height int, width int) (int, error) {
21+
if height <= 0 || width <= 0 {
22+
return 0, errors.New("Height or width is less than 1")
23+
}
24+
return (height * width), nil
25+
}

‎Function-as-closure.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
sum := getSum(10, 10)
7+
fmt.Println(sum())
8+
fmt.Println(sum())
9+
10+
}
11+
12+
func getSum(a, b int) func() int {
13+
i := a + b
14+
15+
return func() int {
16+
i++
17+
return i
18+
}
19+
20+
}

‎Function-as-value.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
sum := getSum(10, 20)
9+
fmt.Println(sum)
10+
11+
}
12+
13+
func getSum(a, b int) int {
14+
return (a + b)
15+
}

‎Function-call-by-reference.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
7+
var a, b uint8
8+
a = 10
9+
b = 12
10+
11+
swap(&a, &b)
12+
13+
fmt.Println("a: ", a, " ,b: ", b)
14+
}
15+
16+
func swap(a, b *uint8) {
17+
x := *a
18+
*a = *b
19+
*b = x
20+
}

‎Function-call-by-value.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
var a, b uint8
7+
a = 10
8+
b = 12
9+
10+
x, y := swap(a, b)
11+
12+
fmt.Println("a: ", x, " ,b: ", y)
13+
}
14+
15+
func swap(a, b uint8) (uint8, uint8) {
16+
return b, a
17+
}

‎HelloWorld.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("Hello World")
7+
fmt.Printf("%v\n", 123.00)
8+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /