Breakable loop in Scratch

Breakable loop in Scratch

https://stackoverflow.com/questions/30682144/breakable-loop-in-scratch

 

Breakable loop in Scratch ?

How do you make a breakable loop in Scratch? I'm using Scratch 2.0 and can't find any good way to make a loop breakable, from inside of the loop itself.

 

Disclaimer:

There is no perfect way to do it. If you can possibly stand this true fact then feel free to continue.


There are a few different ways you could do it.

With repeat until

The first and most simple one follows this:

But this isn't technically part of the script - it's just repeating until some value returns true.

With a custom block (stop this script)

In order to do it inside of the script, you'll need to use a sneaky little trick with custom blocks.

Create a custom block called whatever you want - but probably along the lines of "breakable loop". Inside of it, create this script:

By using stop script we are breaking out of the script that is currently running - which, according to Scratch, is the custom block.

 

See the result! (as scratchblocks)    http://scratchblocks.github.io

 

With broadcast and wait

You could also use a broadcast-and-wait method, very similar to above:

Though I highly suggest you don't use this method, as if any other sprites have breakable loops you'll need to rename each one, which can be tedious after using a lot of loops in a lot of sprites!

 

======================= End

 

posted @   lsgxeva  阅读(304)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2018-02-28 WEB应用安全解决方案测试验证
点击右上角即可分享
微信分享提示