From 5350ed68f6a8ab89e6104b04fdbdf4abe69a2a2a Mon Sep 17 00:00:00 2001 From: Boukabouya Date: Sun, 31 Dec 2023 06:13:16 +0100 Subject: [PATCH 1/2] Evaluate expressions with switch statements --- hello/main.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hello/main.go b/hello/main.go index 8ab932f..7fa3c3c 100644 --- a/hello/main.go +++ b/hello/main.go @@ -2,8 +2,24 @@ package main import ( "fmt" + "math/rand" + "time" ) func main() { - fmt.Println("Hello from Go!") + fmt.Println("Evaluate expressions with switch statements") + rand.Seed(time.Now().Unix()) + dow := rand.Intn(7) + 1 + fmt.Println("Day", dow) + + var result string + switch dow { + case 1: + result = "Monday" + case 2: + result = "Tuesday" + default: + result = "it's another day" + } + fmt.Println(result) } From 2319ceaa4fa07eeefcc0f0c40fdcaf6f81a5441c Mon Sep 17 00:00:00 2001 From: Boukabouya Date: Sun, 31 Dec 2023 10:05:34 +0100 Subject: [PATCH 2/2] Evaluate expressions with switch statements --- hello/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hello/main.go b/hello/main.go index 7fa3c3c..f06ecbb 100644 --- a/hello/main.go +++ b/hello/main.go @@ -9,15 +9,15 @@ import ( func main() { fmt.Println("Evaluate expressions with switch statements") rand.Seed(time.Now().Unix()) - dow := rand.Intn(7) + 1 - fmt.Println("Day", dow) var result string - switch dow { + switch dow := rand.Intn(7) + 1; dow { case 1: result = "Monday" + fallthrough case 2: result = "Tuesday" + //fallthrough // make the control flow less predictable default: result = "it's another day" }