Discuss Scratch

kevinkrt4
Scratcher
13 posts

Need "break" and "continue" blocks for use in repeat loops.

I don't see any way to do “break” or “continue” in a repeat loop.

These are pretty standard mechanisms in other languages to control loop iteration.

Does the scratch team have any plans to add them?

In the mean time, does anyone have a work-around?


MegaApuTurkUltra
Scratcher
1000+ posts

Need "break" and "continue" blocks for use in repeat loops.

I agree it's annoying

Break => put loop in custom block and use stop this script

Continue => replace with if statement inside loop

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
kevinkrt4
Scratcher
13 posts

Need "break" and "continue" blocks for use in repeat loops.

Thank you for your reply MegaApuTurkUltra.

I'll try to figure out how to implement your suggestions.

I believe one of the one of the benefits of object oriented programming is to make it easy to re-use code (objects). Another programming rule I try to follow is to “not write the same code twice”. I'm pretty good at this in other programming languages, but it doesn't seem scratch provides the tools I need. Maybe I'll figure it out as I learn more.

If I am able to implement your suggestions I'll post the code.

gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Need "break" and "continue" blocks for use in repeat loops.

kevinkrt4 wrote:

Thank you for your reply MegaApuTurkUltra.

I'll try to figure out how to implement your suggestions.

I believe one of the one of the benefits of object oriented programming is to make it easy to re-use code (objects). Another programming rule I try to follow is to “not write the same code twice”. I'm pretty good at this in other programming languages, but it doesn't seem scratch provides the tools I need. Maybe I'll figure it out as I learn more.

If I am able to implement your suggestions I'll post the code.

MegaApuTurkUltra wrote:

Break => put loop in custom block and use stop this script
generic loop {
foo::grey
if <pred::grey> then
baz::grey
break::control cap
end
bar::grey
}::control
is equivalent to
generic loop {
__helper_proc_n::custom
}::control
define __helper_proc_n
foo::grey
if <pred::grey> then
baz::grey
stop [this script v]
end
bar::grey

MegaApuTurkUltra wrote:

Continue => replace with if statement inside loop
generic loop {
foo::grey
if <pred::grey> then
baz::grey
continue::control cap
end
bar::grey
}::control
is equivalent to
generic loop {
foo::grey
set [__skip? v] to [false]
if <pred::grey> then
baz::grey
set [__skip? v] to [true]
end
if <(__skip?) = [false]> then
bar::grey
end
}::control
kevinkrt4
Scratcher
13 posts

Need "break" and "continue" blocks for use in repeat loops.

Thank you very much for the excellent examples.

I'll experiment with them to burn them into memory.

Powered by DjangoBB