From 0d06277c47f7c30da8ad1aeb5b3b748778e67911 Mon Sep 17 00:00:00 2001 From: qwq Date: Sat, 6 Dec 2025 18:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E7=9D=A1=E8=A7=89=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 8.if.go | 60 ++++++++++++++++++++++++++++++ 8.switch语句.go => 9.switch语句.go | 0 2 files changed, 60 insertions(+) create mode 100644 8.if.go rename 8.switch语句.go => 9.switch语句.go (100%) diff --git a/8.if.go b/8.if.go new file mode 100644 index 0000000..6a66cb1 --- /dev/null +++ b/8.if.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" +) + +func main() { + if_1() + if_2() +} + +func if_1() { + // 中断式 / 卫语句 + var age int + fmt.Println("输入你的年龄/中断式") + + n,err := fmt.Scan (&age) // 读取输入的年龄 + fmt.Println(age,n,err) // 输出输入的年龄 + + if age <= 0 { + fmt.Println("骗傻子呢!!") + return + } + if age <= 18 { + fmt.Println("哇!!小盆友欸!!") + return + } + + if age <= 35 { + fmt.Println("哇!!你竟然成年了啊!!!不信!!!") + return + } + fmt.Println("你过关!!!") + +} + +func if_2() { + // 嵌套式 + var age int + fmt.Println("输入你的年龄") + + n,err := fmt.Scan (&age) // 读取输入的年龄 + fmt.Println(age,n,err) // 输出输入的年龄 + + if age <=18 { + if age <= 0 { + fmt.Println("没出生") + } else { + fmt.Println("未成年") + } + } else { + if age <= 35 { + fmt.Println("青年") + } + + if age > 35 { + fmt.Println("包可以啊!!") + } + } +} \ No newline at end of file diff --git a/8.switch语句.go b/9.switch语句.go similarity index 100% rename from 8.switch语句.go rename to 9.switch语句.go