From Test-Scratch-Wiki

重複直到 ()
重複直到 ()
類別 控制類積木
形狀 條形積木
加入於 1.1

The Repeat Until () 積木 is a 控制類積木 and a 半框形積木. Blocks held inside this block will loop until the specified 菱形積木 statement is true, in which case the code beneath the block (if any) will execute. This loop is in similar nature to a while loop in some other 程式語言.

用法示例

As this block loops pieces of code until a condition is true, the block is the best way to run code until a desired condition has been reached. Some common uses:

  • Moving a sprite until its X or y 座標 is at a certain amount
重複直到 <(x座標) = [100]> 
  移動 (10) 點
end
  • Having a sprite stick to the mouse until the mouse is not down
重複直到 <<滑鼠鍵被按下?> 不成立> 
  定位到 [鼠標 v] 位置
end
  • Waiting for an event while performing an action
重複直到 <condition> 
  . . .
end
計時器重置
重複直到 <(計時器) > (limit)> 
  . . .
end

應用

Main article: List of Block Workarounds

This block can be worked around with the following code:

重複無限次 
  . . .
  如果 <condition> 那麼 
    廣播訊息 [next v]
    停止 [這個程式 v]
  end
end
當收到訊息 [next v]
. . .

These can break scripts and should be avoided when making 一角色一腳本類專案 專案, however.

參見

Cookies help us deliver our services. By using our services, you agree to our use of cookies.