From Test-Scratch-Wiki

类别 控制类积木
形状 半框形积木

The Forever 积木 is a 控制类积木 and a 半框形积木. Blocks held inside this block will be in a loop — just like the 重复 () 次 block and the 重复直到 () block, except that the loop never ends (unless the 停止标志 is clicked, the 停止全部 block is activated, or the 停止程式 block is activated within the loop). Due to this infinite loop, the block has no bump at the bottom; having a bump would be pointless, as the blocks below it would never be activated.

This block has a slight delay, so for optimum speed of execution, single frame block stacks should be used.

An example of the behavior of a forever loop


The block is one of the most commonly used blocks in Scratch because there are a lot of cases when an infinite loop is needed. Some common uses are:

  • Keeping a sprite at another's location
  定位到 [角色1 v] 位置
  • A music loop
  播放音效 [Battle theme v] 到底
  重複 (12) 次 
    左轉 @turnleft (3) 度
  重複 (12) 次 
    右轉 @turnright (3) 度


Main article: List of Block Workarounds

This block can be replicated in two ways: With a 菱形积木 statement that will never be true, or through 递归.

With the boolean method, the 重复直到 () block is used, along with the boolean statement. There are many that will never be true, including:

<[1] = [-1]>

<[a] = [b]>

<(計時器) = [-1]>

<<<> 不成立> 不成立>

A full workaround:

重複直到 <[1] = [-1]> 
  . . .

One method that does not involve false boolean statements is tail recursion. Tail recursion can be created by a script broadcasting the 广播 needed to start it, thus repeatedly running the script:

當收到訊息 [Recursion v]
. . .
廣播訊息 [Recursion v]

This has some benefits to making projects. For example, the script is helpful since it can be used to create fractals.

This also works:

重複 ([10^ v] \( (309) \)) 次 
  . . .

This requires an operator that reports "Infinity", like:

([10^ v] \( (309) \))

([e^ v] \( (1000) \))

(字串組合 [Infinity] 和 [])

All of these will work in the last workaround.


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