| Forever | |
forever | |
| Category | Control |
| Type | C, Cap Block |
| Introduced in | 11Oct03 (0.x) |

The Forever block is a Control block, a C block, and a Cap 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, or a Stop () cap 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.
Example Uses
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 (sprite 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
Delays
The loop will wait until the next frame after each iteration, provided there are blocks running in the project that require a "yield". At 30 FPS this delay is approximately 1/30 sec. This delay can be avoided by turning on turbo mode.
It can be run inside a custom block set to run without screen refresh but it is not recommended unless it is guaranteed to stop using a stop [ v] block set to stop "this script" or "all". It will cause extreme lag otherwise as Scratch doesn't get a chance to run anything else.
Workaround
- Main article: List of Block Workarounds
The boolean condition of the Repeat Until () block defaults to false when empty, resulting in it running forever:
repeat until <> . . .
The repeat block can be given a really high number. The number Infinity will make it repeat forever. An operator that reports infinity such as dividing 1 by 0 can be used:
repeat ((1) / (0)) . . . end
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.