Discuss Scratch

Catzcute4
Scratcher
500+ posts

New Block to act like a break statement

Kazomix wrote:

have you forgotten scratch is full of work-aroundable things?
Yes, but technically, basically all of scratch is work-around able. In fact, technically we wouldn’t need addition and multiplication: just use the inverses or make your own virtual machine. However, that’s just not ever practical. This is why “there’s a work around” is not valid. Look at this: Say you want a loop to go 50 times or stop if a condition is met while it’s running. Currently you have to do this:
set [i v] to (0)
repeat until <<(i)=(50)> or <condition :: grey > :: operator {
change [i v] by (1)

end
But with this block you could do this:
repeat (50) :: control{

if <condition :: grey > then :: control {
stop [this loop v] :: control
end
end
Which way do you think is more readable: the first one, or the second one? I think the second one is more readable, because it explicitly tells us that we’re looping 50 times, but we stop if there’s a certain condition met. Plus, it’s way more clear we’re repeating if we aren’t using a helper variable, and if we do use the variable, it’s way more bulkey. Readability is also important in coding. Not only that, but option 2 also tells the reader that we’re specifically stopping the loop when a condition occurs, which is far less obvious in option 1.

Last edited by Catzcute4 (March 20, 2024 21:56:49)

Catzcute4
Scratcher
500+ posts

New Block to act like a break statement

gdfsgdfsgdfg wrote:

Maybe this is better
forever {
stop [this loop v]
} :: control :: loop
when you put a stop [ v] block
in the forever loop then this option is available
That’s when you use repeat until. It’s less weird in that case.

Last edited by Catzcute4 (Feb. 16, 2024 23:29:28)

BringUpYourPost
Scratcher
500+ posts

New Block to act like a break statement

uh –>
stop [ this script v]
Malicondi
Scratcher
1000+ posts

New Block to act like a break statement

BringUpYourPost wrote:

uh –>
stop [ this script v]
That stops the entire script, including scripts after the loop that you may want to be run, although there is a workaround i think this would be a incredibly helpful solution (seeing as i use this all the time in python and java)
support
medians
Scratcher
1000+ posts

New Block to act like a break statement

Bringing this topic up.
starlightsparker
Scratcher
1000+ posts

New Block to act like a break statement

MegaApuTurkUltra wrote:

Support but there is a workaround. Put your loop in a custom block and then do
define DoLoop
set [i v] to [0]
repeat (length of [list v])
if <(item (i) of [list v]) = [John]> then
stop [this script v]
end
change [i v] by [1]
end

when gf clicked
DoLoop
say (i) // shows the index of John in list
I’m pretty sure that stops the entire script of the Sprite including code blocks outside that one block
-cloudcoding-
Scratcher
1000+ posts

New Block to act like a break statement

Support, I have looked for this block when starting scratch and just couldn't find it.
starlightsparker
Scratcher
1000+ posts

New Block to act like a break statement

Can’t you use this?
repeat until <(variable) = [value]>


end
Malicondi
Scratcher
1000+ posts

New Block to act like a break statement

starlightsparker wrote:

Can’t you use this?
repeat until <(variable) = [value]>


end
it would be
repeat until <<(variable) = [value]> or <(runs) = [how many repeats]>>
...
change [runs v] by (1)
but a break loop would be so much simpler and easier to use
Catzcute4
Scratcher
500+ posts

New Block to act like a break statement

Malicondi wrote:

starlightsparker wrote:

Can’t you use this?
repeat until <(variable) = [value]>


end
it would be
repeat until <<(variable) = [value]> or <(runs) = [how many repeats]>>
...
change [runs v] by (1)
but a break loop would be so much simpler and easier to use
and it would make clear what you’re doing
-effortIess-
Scratcher
100+ posts

New Block to act like a break statement

Bump
medians
Scratcher
1000+ posts

New Block to act like a break statement

Bringing this topic up.
Catzcute4
Scratcher
500+ posts

New Block to act like a break statement

bumpybumpitybump
MagentaDude1359
Scratcher
100+ posts

New Block to act like a break statement

love it, support
hypercode96
Scratcher
100+ posts

New Block to act like a break statement

omg yes yes so support
Catzcute4
Scratcher
500+ posts

New Block to act like a break statement

another reason t use this: basically every real programming language has a break; statement, like js, and even Blockly has it in its demos
medians
Scratcher
1000+ posts

New Block to act like a break statement

Bringing this topic up.
Catzcute4
Scratcher
500+ posts

New Block to act like a break statement

oh also another thing, it should be mentioned that the stop this script does work as a custom block ender, but only for that. plus it’s kinda confusing that it works
Creator-H
Scratcher
100+ posts

New Block to act like a break statement

bump
turtleman885
Scratcher
64 posts

New Block to act like a break statement

theonlygusti wrote:

set [i v] to [0]
repeat (length of [list v])
if <(item (i) of [list v]) = [John]> then
exit this loop :: control cap //I think this should be just exit loop
end
change [i v] by [1]
end
say (i) // shows the index of John in list

turtleman885 wrote:

SUPPORT!

Last edited by turtleman885 (March 30, 2025 16:05:34)

Powered by DjangoBB