Discuss Scratch
- Discussion Forums
- » Suggestions
- » New Block to act like a break statement
- theonlygusti
-
1000+ posts
New Block to act like a break statement
I suggest a block to break out of loops, like in many other programming languages. In another programming language, it might look like this (pseudo-code):
Then you would have the index of “John” stored in the variable i. Basically, a break statement exits a loop.
In Scratch I think it could look like:
Of course, this is just an example, and I know that there are many work-arounds, but I think it is just an extremely useful feature to have, and (pretty much) every other programming feature implements this statement, so by including it Scratch would introduce another feature central to other languages, which is the point of Scratch anyway.
I used the name “exit this loop” because the name break might have been confusing to new Scratchers. See here for a list of all possible names, and suggest your own: http://scratch.mit.edu.ezproxyberklee.flo.org/discuss/topic/53810/?page=1#post-453542
It could also be an extra option in the stop () block, see the link for design ideas.
var i = 0;
foreach person as name {
if name == "John" {
break;
}
i++;
}
Then you would have the index of “John” stored in the variable i. Basically, a break statement exits a loop.
In Scratch I think it could look like:
set [i v] to [0]
repeat (length of [list v])
if <(item (i) of [list v]) = [John]> then
exit this loop :: control cap
end
change [i v] by [1]
end
say (i) // shows the index of John in list
Of course, this is just an example, and I know that there are many work-arounds, but I think it is just an extremely useful feature to have, and (pretty much) every other programming feature implements this statement, so by including it Scratch would introduce another feature central to other languages, which is the point of Scratch anyway.
I used the name “exit this loop” because the name break might have been confusing to new Scratchers. See here for a list of all possible names, and suggest your own: http://scratch.mit.edu.ezproxyberklee.flo.org/discuss/topic/53810/?page=1#post-453542
It could also be an extra option in the stop () block, see the link for design ideas.
stop [this loop v] :: control cap
Last edited by theonlygusti (Sept. 2, 2015 15:28:53)
- theonlygusti
-
1000+ posts
New Block to act like a break statement
2nd time you've supported a work-aroundable thing ? Support.

- stickfiregames
-
1000+ posts
New Block to act like a break statement
Support, but the name “break” might confuse new Scratchers. These might be better:
exit this loop :: control
skip to end of loop :: control
exit repeat :: control // repeat and repeat until are the only loops this needs to be used in, forever can use stop script.
Last edited by stickfiregames (Sept. 28, 2014 14:19:04)
- theonlygusti
-
1000+ posts
New Block to act like a break statement
Good suggestion. I'll add a new name to the top, and create a new post with naming suggestions. Thanks Support, but the name “break” might confuse new Scratchers. These might be better:exit this loop :: control
skip to end of loop :: control

- theonlygusti
-
1000+ posts
New Block to act like a break statement
exit this loop :: control stack
exit this loop :: control cap // cap design, might be more fitting as it's the "end" of a loop
break :: control stack
break :: control cap
stop loop :: control stack
stop loop :: control cap
leave this loop :: control stack
leave this loop :: control cap
Leave your own naming suggestions, and whether you think they should be cap or stack blocks.
So far more support has been shown towards cap blocks. I will update all my ideas.
Maybe we could add a drop down to the "stop " block:
stop [this loop v]
Last edited by theonlygusti (Sept. 28, 2014 15:42:26)
- stickfiregames
-
1000+ posts
New Block to act like a break statement
Caps make more sense.exit this loop :: control stack
exit this loop :: control cap // cap design, might be more fitting as it's the "end" of a loop
break :: control stack
break :: control cap
stop loop :: control stack
stop loop :: control cap
leave this loop :: control stack
leave this loop :: control cap
Leave your own naming suggestions, and whether you think they should be cap or stack blocks.
- MegaApuTurkUltra
-
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 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
- theonlygusti
-
1000+ posts
New Block to act like a break statement
I know that there are several workarounds, I said so in the original post. Thanks for the support anyhow! Support but there is a workaround. Put your loop in a custom block and then do...
Last edited by theonlygusti (Sept. 28, 2014 15:34:46)
- Blueinkproductions
-
1000+ posts
New Block to act like a break statement
when green flag clicked
set [i v] to [0 ]
repeat until <[2] = [ 1]>
say [Support!] for (1) secs
change [i v] by (1)
if <(i) > [1000 ]> then
exit this loop :: control cap
end
end
- theonlygusti
-
1000+ posts
New Block to act like a break statement
XDwhen green flag clicked
set [i v] to [0 ]
repeat until <[2] = [ 1]>
say [Support!] for (1) secs
change [i v] by (1)
if <(i) > [1000 ]> then
exit this loop :: control cap
end
end
- theonlygusti
-
1000+ posts
New Block to act like a break statement
when green flag clicked
set [i v] to [0 ]
repeat until <[2] = [ 1]>
say [Support!] for (1) secs
change [i v] by (1)
if <(i) > [1000 ]> then
exit this loop :: control cap
end
end
say [i = 1001, this is awesome!]
- ProdigyZeta7
-
1000+ posts
New Block to act like a break statement
Support. Regardless of a workaround I find it tedious to make as few scripts/variables while escaping loops.
- Tropic
-
1000+ posts
New Block to act like a break statement
Isn't foreach from Java? 
(Support, because I like Java and maybe I can get more used to Java if this gets implemented
)

(Support, because I like Java and maybe I can get more used to Java if this gets implemented

- theonlygusti
-
1000+ posts
New Block to act like a break statement
foreach is from a load of languages, php, java, … Isn't foreach from Java?
(Support, because I like Java and maybe I can get more used to Java if this gets implemented)
- Tropic
-
1000+ posts
New Block to act like a break statement
Oh, okforeach is from a load of languages, php, java, … Isn't foreach from Java?
(Support, because I like Java and maybe I can get more used to Java if this gets implemented)

- theonlygusti
-
1000+ posts
New Block to act like a break statement
Tropic, have you been on for the past 10 hours? Non-stop?
- Discussion Forums
- » Suggestions
-
» New Block to act like a break statement