<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                前一習題中你寫了一些「if 語句 (if-statements)」,并且試圖猜出它們是什么,以及實現的是什么功能。在你繼續學習之前,我給你解釋一下上一節的加分習題的答案。上一節的加分習題你做過了吧,有沒有? 1. 你認為 if 對于它下一行的代碼做了什麼?`if` 語句為代碼創建了一個所謂的「分支(branch)」,就跟 RPG游戲中的情節分支一樣。if 語句告訴你的腳本:「如果這個布爾表達式為真,就執行接下來的代碼,否則就跳過這一段。」 2. 把習題29中的其它布爾表達式放到 if 語句中會不會也可以執行呢?試一下。可以。而且不管多復雜都可以,雖然寫復雜的東西通常是一種不好的寫作風格。 3. 如果把變量 people、cats和 dogs 的初始值改掉,會發生什么事情?因為你比較的對象是數字,如果你把這些數字改掉的話,某些位置的 if 語句會被演繹為 True,而它下面的程序區段將被運行。你可以試著修改這些數字,然后在頭腦里假想一下那一段代碼會被運行。 把我的答案和你的答案比較一下,確認自己真正懂得代碼「區段(block)」的含義。這點對于你下一節的習題練習很重要,因為你將會寫很多的if 語句。 把這一段寫下來,并讓它運行起來: ~~~ people = 30 cars = 40 buses = 15 if cars > people puts "We should take the cars." elsif cars < people puts "We should not take the cars." else puts "We can't decide." end if buses > cars puts "That's too many buses." elsif buses < cars puts "Maybe we could take the buses." else puts "We still can't decide." end if people > buses puts "Alright, let's just take the buses." else puts "Fine, let's stay home then." end ~~~ # 你應該看到的結果 * * * * * ~~~ $ ruby ex30.rb We should take the cars. Maybe we could take the buses. Alright, let's just take the buses. $ ~~~ # 加分習題 * * * * * 1. 猜想一下 `elsif` 和 `else` 的功能。 2. 將 `cars`、`people`和`buses`的數量改掉,然后追溯每一個if語句。看看最后會輸出什么。 3. 試著寫一些復雜的布爾表示達式,例如` cars > people and buses < cars`。 在每一行的上面寫注釋,說明這一行的作用。
                  <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>

                              哎呀哎呀视频在线观看