请问一下这代码为什么没有运行结果啊(for+switch)

haozi · · 1013 次点击
下面是代码的原文哈 package main import( "fmt" "math/rand" ) func main(){ const num0 = 55 var num = rand.Intn(100) + 1 for num == num0{ switch{ case num == num0: fmt.Println("U r right! The value is ",num0,"!") case num > num0: fmt.Println("The value should be greater!") num = rand.Intn(100) + 1 case num < num0: fmt.Println("The value should be less!") num = rand.Intn(100) + 1 } } }
#1
更多评论
把 for 删了不就完了 💦
#2
package main import( "fmt" "math/rand" ) func main(){ const num0 = 55 var num = rand.Intn(100) + 1 re: for { switch { case num == num0: fmt.Println("U r right! The value is ",num0,"!") break re case num > num0: fmt.Println("The value should be greater!") num = rand.Intn(100) + 1 case num < num0: fmt.Println("The value should be less!") num = rand.Intn(100) + 1 } } }
#3