(Go)10.流程控制示例

 1 package main
 2 
 3 import (
 4     "math/rand"
 5     "fmt"
 6 )
 7 
 8 
 9 func main() {
10     //var n int 
11     n := rand.Intn(100)
12 
13     for {
14         var input int 
15         fmt.Scanf("%d\n", &input)
16         flag := false
17         switch {
18         case input == n:
19             fmt.Println("you are right!")
20             flag = true
21         case input > n:
22             fmt.Println("bigger!")
23         case input < n:
24             fmt.Println("less!")
25         }
26 
27         if flag {
28             break
29         }
30 
31     }
32 }

输出结果:

 

posted @ 2019-01-30 10:28  lvelvis  阅读(215)  评论(0编辑  收藏  举报
#####