Discuss Scratch
- PH-zero
-
100+ posts
Switch-block
Hey 
Have you already encountered this:
In most of all programming-languages there is a “switch” statement.
In scratch The implementation might be difficult…
but i could imagine something like this:
This is just an example of how a switch block could be realized.
But it definetly can be desinged in a way that new scratchers don't get confused.

Have you already encountered this:
In most of all programming-languages there is a “switch” statement.
In scratch The implementation might be difficult…
but i could imagine something like this:
Exept the switch-block would be one big brace rather than to seperate blocks.
This is just an example of how a switch block could be realized.
But it definetly can be desinged in a way that new scratchers don't get confused.
Last edited by PH-zero (Aug. 12, 2014 18:31:30)
- mobluse
-
100+ posts
Switch-block
I usually do it with if else because I think it's faster, but there is a workaround for switch using broadcast, see below.
Alternative to switch:
Alternative to switch:
(Edit: fixed looks of variable.)
Last edited by mobluse (March 8, 2014 23:03:07)
- seanbobe
-
500+ posts
Switch-block
not a bug. I usually do it with if else because I think it's faster, but there is a workaround for switch using broadcast, see below.
Alternative to switch:(BTW there is a bug in Scratchblocks here, since the variable isn't shown as a variable.)
- blob8108
-
1000+ posts
Switch-block
There is a bug in the drop-down blocks menu, yes. But the plugin does allow it:(BTW there is a bug in Scratchblocks here, since the variable isn't shown as a variable.)
broadcast (letter) and wait
EDIT: Anyway, have a mockup of a “switch”, just for fun:
But really we want the cases embedded in the switch somehow:
And the wording could be improved, too:
…but then this does make one question why we don't just have “else if” instead.
Last edited by blob8108 (March 1, 2014 21:31:11)
- Firedrake969
-
1000+ posts
Switch-block
Would we want optional breaks or not? Mockup:Anyway, support.
- davidkt
-
1000+ posts
Switch-block
Not. It would be too confusing, and there aren't going to be many circumstances where you'll need to not have the break.Would we want optional breaks or not? Mockup:Anyway, support.
- A-no-meep
-
100+ 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.Would we want optional breaks or not? Mockup:Anyway, support.
- Scratcher1002
-
1000+ posts
Switch-block
You could, but it gets annoying when you have to do 100 ifs like: Umm … couldn't you just nest some If's? …
- CatsUnited
-
1000+ posts
Switch-block
What is a switch statement? I haven't learnt enough of any programming language to know what it is.
- Scratcher1002
-
1000+ posts
Switch-block
Normally it's an if block with many cases, but one variable like this: What is a switch statement? I haven't learnt enough of any programming language to know what it is.
Javascript:
switch (variable)
case 1
break
case 2
break
default
- CatsUnited
-
1000+ posts
Switch-block
I know what they are in PHP now.Normally it's an if block with many cases, but one variable like this: What is a switch statement? I haven't learnt enough of any programming language to know what it is.Javascript:
switch (variable)
case 1
break
case 2
break
default
- MegaApuTurkUltra
-
1000+ posts
Switch-block
I support. Not only would this make code less cluttered, but if would also make execution faster as the Scratch interpreter would have an opportunity to use a switch table or something for optimization.
- Lax125
-
14 posts
Switch-block
Support for switch statement blocks; I have messy nested if/else's in my script.