one thing that computers are really good
at is repeating commands as a person you
get really bored if you had to do the
same thing lots of times in a row but a
computer can do the same thing millions
or even billions of times and not get
bored and be able to carry that out
really well
so for example if I wanted to wish
everyone on facebook a happy birthday by
sending them an email it might take me
more than a century to actually write
out all of those emails to everyone but
with just a few lines of code i can have
a system send an email to everyone on
facebook wishing them a happy birthday
so that's what loops are and why they're
valuable and something that computers
can do very well in this example your
goal is going to be to move the bird now
we're going to be able to use the repeat
block in order to be able to do this
very easily you can either do this by
giving the computer and move forward
command five times in order to advance
the the bird one step each time to the
pig or you can just tell the computer to
move forward once and then tell it to
repeat that five times and it will do
the same thing so in order to do this
you drag your move forward command and
then you put it inside the repeat block
and you can click on it and tell it how
many times you want to repeat the block
to tell how many steps you wanted to
take forward now one more thing is you
can put as many commands as you want
inside the repeat block so in this
example your tongue it to move forward
and turn left which will do five times
alright good job and have fun
コンピューターが、とくいなこと
それは、コマンドをくりかえすこと。
人は、同じことを ずっと やれ と
いわれたら あきるよね。
でも、コンピューターは、何百万回でも
何おく回でも 同じことが できるんだ。
あきずに、
せいかくにね。
たとえば、Facebookのすべての人に
ハッピーバースデーのメールを
おくろうとしたら
それだけで100年以上
かかるかもしれません。
しかし、数行のコードで
すべての人にハッピーバースデーの
メールをおくれるんだ。
ループをつかう いみは、ここにあるんだ。
これがループが、やくだつ りゆう。
そして、コンピューターは、ループが、とくいだ。
このかいのゴールは、トリを動かすこと。
かんたんにクリアするために
くりかえしブロックを使ってみよう。
トリは1つのめいれいで
1つ前に進むから
ブタをつかまえるには、
[前にすすむ]を5つならべるか
[前にすすむ]は1つで
それを5回
くりかえすのか どっちかだ。
どっちでも けっかは、同じ。
[前にすすむ]をドラックして
くりかえしブロックの中に入れる。
くりかえしブロックをクリックして
前に進む数と
かいすうに 同じ数字を 書く。
それから、もう一つ
くりかえしブロックの中は
すきなだけブロックを入れることができる。
たとえば、「前に進む」 と「 左にまがる」 を
5回くり返すこともできる。
がんばって、たのしんでね
有件事情是電腦非常擅長的…
那就是重複指令。身為一個人,
你會很厭煩的,如果你必須
做同樣的事情很多遍,
但是電腦可以把同樣的事情
做上數百萬,甚至數十億次,
它們也不會感到無聊,
也能夠完美的勝任它。
舉例來說,如果我希望祝福
每個在 Facebook 的人生日快樂,
透過寄送電子郵件的方式,可能要
花上我超過一世紀的時間才能寫完
所有這些郵件給大家,
但透過幾行的程式碼,我就能
有個系統來寄信給所有在
Facebook 上的人並祝他們生日快樂。
這個系統就是所謂的迴圈(loops),
是它們的價值所在,也是電腦
很擅長的事情,在這個例子中,
你的目標是移動憤怒鳥抓到豬,
我們就可以用上重複積木,
來輕鬆的完成這個目標。
當然你也可以完成這個,透過
給電腦向前移動的指令五次,
讓憤怒鳥一步步的走向豬,
或者,你可以告訴電腦
向前走一格,然後告訴它重複
五次, 它就會執行這些事情了。
要做到這一個,你可以
拖曳移動向前指令,
接著把放進重複積木,
然後你在上頭點一下,
告訴它你想要重複執行的次數,
這次數就是你想要向前的步數,
還有件事,你可以放進很多
指令到重複積木裡, 就像是
例如接著轉向往上移動,
它就會執行這件事五次,
好啦,開始工作了,玩得開心點!