<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                流程控制 1、if 基本語法 if condition { do something } ~~~ package main import( "fmt" ) func main() { num := 10 if num % 2 == 0 { fmt.Println("num is even") }else { fmt.Println("num is odd") } } ~~~ 2、if statement;condition { } ~~~ package main import( "fmt" ) func main() { if num := 10;num % 2 == 0 { fmt.Println("num is even") }else { fmt.Println("num is odd") } } ~~~ 3、for循環 break終止循環,跳出循環 continue 終止本次循環,繼續下面的循環 4、無限循環 ~~~ func fort() { for { fmt.Printf("hello\n") time.Sleep(time.Second) } } ~~~ switch語句: 1、 ~~~ func switchtest() { finger := 4 switch finger{ case 1 : fmt.Println("first") case 2: fmt.Println("second") case 3: fmt.Println("third") case 4: fmt.Println("fourth") case 5: fmt.Println("fiveth") } } ~~~ fallthrough 匹配到值后自動執行下一個匹配項,然后退出循環。 default 默認當所有匹配項都匹配不上時的執行內容 ~~~ func switchtest() { finger := 10 switch finger{ case 1 : fmt.Println("first") fallthrough case 2: fmt.Println("second") case 3: fmt.Println("third") case 4: fmt.Println("fourth") case 5: fmt.Println("fiveth") default: fmt.Println("other is not in list") } } ~~~ 2、case語句中的判斷: ~~~ func SwitchIfTest() { num := 75 switch { case num >= 0 && num <= 50: fmt.Println("num is greater than 0 and less than 50") case num >= 51 && num <= 100: fmt.Println("num is greater than 51 and less than 100") case num >= 101: fmt.Println("num is greater than 100") } } ~~~ 練習:程序生成隨機數字,用戶輸入,猜對了退出 ~~~ package main import( "fmt" "math/rand" ) func main() { //根據時間生成隨機數的總和 rand.Seed(time.Now().UnixNano()) number := rand.Intn(100) fmt.Printf("請輸入一個數字,數字的范圍:[0-100]\n") for { var input int fmt.Scanf("%d\n",&input) var flag bool = false switch { case number > input: fmt.Printf("你輸入的數字太小\n") case number == input: fmt.Printf("恭喜你,猜對了\n") flag = true case number < input: fmt.Printf("你輸入的數字太大\n") } if flag { break } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看