Discuss Scratch
- GarryHatesScratch
-
Scratcher
1 post
Switch-block
Something like this would be cool:
switch (letter) {
case [a] {
} :: control
case [b] {
} :: control
case [c] {
}:: control
} :: control- banana439monkey
-
Scratcher
1000+ posts
Switch-block
see i would see this:
i was thinking of a
i would love to see it but could probably bring up some form of errors?
Banana
switch (item) :: control // this and the case block would be fused together, other case blocks would not be fused together but can only be used in this context
case [...] {
...
} case [...] {
...
} :: control // this case block and beyond would not be fused to switch. the reason the first case was fused was so that no other blocks can be used underneath switch
case [...] {
...
} :: control
default {
...
} :: control // If none of the cases are met, then do this
i was thinking of a
break :: controlblock but i feel that if a case is met it should break the switch/case statement anyway (else we risk seriously confusing users if multiple cases listed is the case and by default we run through all of the cases that are true)
i would love to see it but could probably bring up some form of errors?
Banana
Last edited by banana439monkey (May 4, 2023 13:41:35)
- -SkysBane-
-
Scratcher
48 posts
Switch-block
Agreed. Most instances of deliberately not having break can be solved with duplicate.Not. It would be too confusing, and there aren't going to be many circumstances where you'll need to not have the break.Mockup:Would we want optional breaks or not?switch (variable) ::control // pretend it's joined with the block belowAnyway, support.
case (1)::cstart control
...
case (2)::celse
...
case (3) + - ::celse
...
default ::celse
...
end
I think you should have a “break” block because it could be used for other things as well, like breaking out of while loops, forever loops, and the switch statement
stop [break v]
The default fallthrough of the switch statement can actually be useful, and I think it would allow for some more efficient and interesting programs. It might be hard for people to learn, but that's what tutorials are for. I think it would be useful for a lot of reasons. The broadcast version of a switch statement is nice, but you can't do fallthrough and it doesn't happen in the same tick.
- ophizma
-
Scratcher
4 posts
Switch-block
set (letter) to (switch)
broadcast (letter)
Last edited by ophizma (Aug. 7, 2023 20:13:24)
- mumu245
-
Scratcher
1000+ posts
Switch-block
Mockup:
// if a case is true, runs the code and exits the switch
switch () {
case () {
. . .
} ::control
case () {
. . .
} ::control
else {
. . .
} ::control cap
} ::control
- Blueshadez
-
Scratcher
26 posts
Switch-block
Support. This addition would teach the kids about switch statements, and it would be great to use for optimization.
- TheBaton
-
Scratcher
500+ posts
Switch-block
Hmm, Yeah, this would make it so much faster, especially if we can extend it with an editor, like you can in the Blockly framework (Scratch uses that.) Support, this would be very useful!
- HappyDay-12
-
Scratcher
12 posts
Switch-block
Support! It would make things so much easier and less cluttered.










