Zho:重复无限次（积木）

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.



用法示例
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] 位置 end


 * A music loop

重複無限次 播放音效 [Battle theme v] 到底 end


 * 动画类专案 (such as a waving hand)

重複無限次 重複 (12) 次 左轉 @turnleft (3) 度 end 重複 (12) 次 右轉 @turnright (3) 度 end end

应用
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]> . . . end

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) \)) 次 . . . end

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

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

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

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

All of these will work in the last workaround.

参见

 * 重复无限次如果
 * 重复 次
 * 重复直到
 * 递归