The Forever block is a Control block and a C block. Blocks held inside this block will be in a loop — just like the Repeat () block and the Repeat Until () block, except that the loop never ends (unless the stop sign is clicked, the Stop All block is activated, or the stop script 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
forever go to [Sprite1 v]
- A music loop
forever play sound [Battle theme v] until done
- Animations (such as a waving hand)
forever repeat (12) turn left (3) degrees end repeat (12) turn right (3) degrees
- Main article: List of Block Workarounds
With the boolean method, the Repeat Until () block is used, along with the boolean statement. There are many that will never be true, including:
< = [-1]> <[a] = [b]> <(timer) = [-1]> <not <not <>>>
A full workaround:
repeat until < = [-1]> . . .
One method that does not involve false boolean statements is tail recursion. Tail recursion can be created by a script broadcasting the broadcast needed to start it, thus repeatedly running the script:
when I receive [Recursion v] . . . broadcast [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:
repeat ([10^ v] of (309)) . . . end
This requires an operator that reports "Infinity", like:
([10^ v] of (309)) ([e^ v] of (1000)) (join [Infinity] ) ((1) / (0))
All of these will work in the last workaround.