|This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective.|
|Forever If ()|
The Forever If () block was a Control block and a C block. The block would continuously check its Boolean condition. If the condition is true, the code held inside the block would run, and then the script continues, but if the condition is false, nothing would happen until it becomes true again. The block continuously runs in a loop; in fact, this block worked just like the If () block placed into the Forever block. After being removed, this block is replaced with its workaround.
- Main article: List of Block Workarounds
This block can be simulated with the following code:
forever if <...> then . . . end end
forever wait until <...> . . . end
forever repeat until <not <...>> . . . end end
In Scratch 2.0, this block is automatically replaced with the first workaround.
Due to the block's simplicity to recreate, that it has less functionality than the replication (you cannot stack multiple If () blocks inside the Forever If () block), and that new Scratchers sometimes confuse it with the Repeat Until () block, there had been many campaigns to remove the block. Eventually in 2.0, the block was removed. The block had an advantage, though: it runs some milliseconds faster than its replication, so it could be used to combat extreme lag.
Using the workaround gives an advantage too — you can place multiple If () statements (and If () Then, Else statements, and even other blocks) in the Forever loop. An example:
forever if <key [1 v] pressed?> then set [Page v] to (1) end if <key [2 v] pressed?> then set [Page v] to (2) end if <key [space v] pressed?> then broadcast [Render v] end end
Some common uses, however, were:
- Reducing lag
forever if <(size) > > :: control ...//laggy script
- Swift script construction
when gf clicked forever if <loud?::sensing> :: control say [Shh... do not wake anyone up.]
- Simple cases where there only needed to be one If () block in a Forever block, so the Forever If () was used instead
forever if <(x position) > > :: control hide