Add Chapter 1: Introduction to Go - Environment setup and Hello World

This commit is contained in:
openclaw
2026-03-23 14:15:41 +00:00
parent 51f36611f7
commit b0ceda8c88
3 changed files with 374 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
module go-tutorial
go 1.21

View File

@@ -0,0 +1,41 @@
package main
import "fmt"
func main() {
// 1. 基础 Hello World
fmt.Println("Hello, World!")
// 2. 多行输出
fmt.Println("这是第一行")
fmt.Println("这是第二行")
fmt.Println("这是第三行")
// 3. 格式化输出
name := "思语"
age := 25
fmt.Printf("你好,我是 %s今年 %d 岁!\n", name, age)
// 4. 简单计算
a := 10
b := 20
fmt.Printf("%d + %d = %d\n", a, b, a+b)
fmt.Printf("%d * %d = %d\n", a, b, a*b)
// 5. 条件判断示例
score := 85
if score >= 90 {
fmt.Println("优秀!")
} else if score >= 80 {
fmt.Println("良好!")
} else {
fmt.Println("继续努力!")
}
// 6. 循环示例
fmt.Println("Counting from 1 to 5:")
for i := 1; i <= 5; i++ {
fmt.Printf("%d ", i)
}
fmt.Println()
}