Discuss Scratch
- Discussion Forums
- » Suggestions
- » 'Break' Block
- Miastonished
-
Scratcher
100+ posts
'Break' Block
This is a new block I want added.
Example:
When the code runs it repeats 1000 times. It will stop when you press space or it will move until the loop finishes.
Example:
Script :: hat events
repeat (1000)
if <key[space v] pressed> then
break [loop 1 v] :: control //The block
end
move (10) steps
end
...
When the code runs it repeats 1000 times. It will stop when you press space or it will move until the loop finishes.
Last edited by Miastonished (Aug. 10, 2017 05:44:50)
- WolfCat67
-
Scratcher
1000+ posts
'Break' Block
How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?
- Miastonished
-
Scratcher
100+ posts
'Break' Block
How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?
Maybe:
Break [Loop v] :: control
The loop part being like a colour picker. Instead for blocks.
- WolfCat67
-
Scratcher
1000+ posts
'Break' Block
So… Every loop would need to be assigned a kind of ID of sorts, and when clicking on it, you'd be able to choose which one?How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?
Maybe:Break [Loop v] :: control
The loop part being like a colour picker. Instead for blocks.
I don't know, seems like quite a lot of work.
- Miastonished
-
Scratcher
100+ posts
'Break' Block
Just something simple like ‘Loop 7’.So… Every loop would need to be assigned a kind of ID of sorts, and when clicking on it, you'd be able to choose which one?How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?
Maybe:Break [Loop v] :: control
The loop part being like a colour picker. Instead for blocks.
I don't know, seems like quite a lot of work.
- kenny2scratch
-
Scratcher
500+ posts
'Break' Block
How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?If statements aren't loops

In the example script, that would break the repeat loop and stop. If the only purpose of that script after breaking is to stop, you can do
script :: events hatThat will stop the script when you press space.
repeat (1000)
if <key [space v] pressed?> then
stop [this script v] // you can just stop the script inside without having to break
end
move (10) steps
end
I do, however, support this block for other reasons (namely, there are certain scripts that do something after breaking).
My main concern with the block would be, again, how easy it is to understand. New Scratchers probably wouldn't get the concept… but otherwise, support.

- Miastonished
-
Scratcher
100+ posts
'Break' Block
What is the purpose of this break block?To get out of a loop.
- Charles12310
-
Scratcher
1000+ posts
'Break' Block
Alternative:
When the space key is pressed, it stops the loop script.
when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end
When the space key is pressed, it stops the loop script.
- Miastonished
-
Scratcher
100+ posts
'Break' Block
Alternative:Example script:when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end
When the space key is pressed, it stops the loop script.
when green flag clicked
repeat (1000) // Randomly Long Intro
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end
Game stuff... :: grey // Game stuff
- duckboycool
-
Scratcher
1000+ posts
'Break' Block
The repeat until block exists for a reason.
set [loops v] to [0]
repeat until <<...> or <(loops) > [999]>>
...
change [loops v] by (1)
end
- Sheep_maker
-
Scratcher
1000+ posts
'Break' Block
Based off duckboycool's workaround, for a general break block:
Maybe
set [break v] to [no]however this workaround won't stop the rest of the loop's scripts.
repeat until <<...>or<(break)=[yes]>>
if (...::grey) then // example script
set [break v] to [yes]
end
end
Maybe
stop [this loop v]since programming language terms are hard to translate to other languages?
- walkcycle
-
Scratcher
500+ posts
'Break' Block
when green flag clicked
set [break v] to [no]
broadcast [loop v]
when I receive [loop v]
if < (break) = [no] > then
repeat until <...>
end
end
define break
set [break v] to [yes]
broadcast [loop v]
break // should arbitrarily break the loop or my scratch-fu is too rusty
- WolfCat67
-
Scratcher
1000+ posts
'Break' Block
Based off duckboycool's workaround, for a general break block:The repeat until is the loop in the example. I've added the loop variable itself to demonstrate it above.set [break v] to [no]however this workaround won't stop the rest of the loop's scripts.
set [loops v] to [0]
repeat until <<(loops) = [999]>or<(break)=[yes]>>
if (...::grey) then // example script
set [break v] to [yes]
end
change [loops v] by (1)
end
- Scratcher1002
-
Scratcher
1000+ posts
'Break' Block
How about:
repeat (1000) {
if <key [space v] pressed?> then
break [grandparent v] :: control
move (10) steps
} :: control
break [parent v] :: control // Stops the c-block the script is in
break [grandparent v] :: control // Stops the parent of the c-block it's in.Last edited by Scratcher1002 (July 4, 2017 16:14:26)
- Charles12310
-
Scratcher
1000+ posts
'Break' Block
Workaround:The way this workaround works is that when an action happens, the script is stopped. However, if you attach other blocks to outside of the repeat script (what I mean is it isn't in the repeat block, it's outside of it, but it still part of the full script).when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end
When the space key is pressed, it stops the loop script.
This example is the opposite:
when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
broadcast [continue v]
stop [this script v]
end
move (10) steps
end
when I receive [continue v]
...
The broadcast button starts another script before breaking the looping script. It's not a “boardcast () and wait” block, so the stop block happens right after the broadcast block is activated.
When the broadcast is received other scripts happen.
I recommend to put a wait block in the “when I receive block” in-case the loop script doesn't stop quickly.
Last edited by Charles12310 (July 5, 2017 02:04:22)
- Miastonished
-
Scratcher
100+ posts
'Break' Block
How about use this block:Have you seen the example script?stop [this script]
- Charles12310
-
Scratcher
1000+ posts
'Break' Block
You mean this one:How about use this block:Have you seen the example script?stop [this script]
Workaround:The way this workaround works is that when an action happens, the script is stopped. However, if you attach other blocks to outside of the repeat script (what I mean is it isn't in the repeat block, it's outside of it, but it still part of the full script).when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end
When the space key is pressed, it stops the loop script.
This example is the opposite:when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
broadcast [continue v]
stop [this script v]
end
move (10) steps
end
when I receive [continue v]
...
The broadcast button starts another script before breaking the looping script. It's not a “boardcast () and wait” block, so the stop block happens right after the broadcast block is activated.
When the broadcast is received other scripts happen.
I recommend to put a wait block in the “when I receive block” in-case the loop script doesn't stop quickly.
- Discussion Forums
- » Suggestions
-
» 'Break' Block