Discuss Scratch
- Discussion Forums
- » Suggestions
- » New Block to act like a break statement
- Catzcute4
-
Scratcher
500+ posts
New Block to act like a break statement
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)But with this block you could do this:
repeat until <<(i)=(50)> or <condition :: grey > :: operator {
change [i v] by (1)
…
end
repeat (50) :: control{
…
if <condition :: grey > then :: control {
stop [this loop v] :: control
end
endWhich 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
Maybe this is betterThat’s when you use repeat until. It’s less weird in that case.forever {when you put a stop [ v] block
stop [this loop v]
} :: control :: loop
in the forever loop then this option is available
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
uh –>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)stop [ this script v]
support
- starlightsparker
-
Scratcher
1000+ posts
New Block to act like a break statement
Support but there is a workaround. Put your loop in a custom block and then doI’m pretty sure that stops the entire script of the Sprite including code blocks outside that one blockdefine 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
- -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
Can’t you use this?it would berepeat until <(variable) = [value]>
…
end
repeat until <<(variable) = [value]> or <(runs) = [how many repeats]>>but a break loop would be so much simpler and easier to use
...
change [runs v] by (1)
- Catzcute4
-
Scratcher
500+ posts
New Block to act like a break statement
and it would make clear what you’re doingCan’t you use this?it would berepeat until <(variable) = [value]>
…
endrepeat until <<(variable) = [value]> or <(runs) = [how many repeats]>>but a break loop would be so much simpler and easier to use
...
change [runs v] by (1)
- 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
- 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
- turtleman885
-
Scratcher
64 posts
New Block to act like a break statement
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
SUPPORT!
Last edited by turtleman885 (March 30, 2025 16:05:34)
- Discussion Forums
- » Suggestions
-
» New Block to act like a break statement










