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
- Main article: List of Block Workarounds
With the boolean method, the 重複直到 () block is used, along with the boolean statement. There are many that will never be true, including:
< = [-1]> <[a] = [b]> <(計時器) = [-1]> <<<> 不成立> 不成立>
A full workaround:
重複直到 < = [-1]> . . . end
當收到訊息 [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.