Discuss Scratch

Gigabyte_Giant
Scratcher
43 posts

Switch Statement

Hello,
I have recently started using Scratch more (I am normally holed up in some other IDE for another programming language), and I have noticed that Scratch does not contain a switch statement.

In Java, a switch statement looks like this:

switch(gameState) {

case “Running”:
playGame();
break;
case “Menu”:
drawMenu();

}

You get the point. Now, with a few Scratch blocks, I can create one, mainly because I know the general idea behind a switch statement. I have outlined it below:

You basically pass a variable (String, Boolean, Integer, Double, Character, etc.), and then you choose a case. Now, for a Boolean this is not really necessary, however, instead of two if blocks (or one if/else block), you could just do as follows:

switch(myBoolean) {

case true:
// Do something
break;
case false:
// Do something
break;

}

Now, I am not sure how you would want to format this as a Scratch block, however, I am sure you could figure something out.

Best Regards,

Gigabyte_Giant
PH-zero
Scratcher
100+ posts

Switch Statement

I already suggested this here: http://scratch.mit.edu/discuss/topic/20351/
support
u8y7541
Scratcher
59 posts

Switch Statement

I do program other languages, so I get you. Good idea!
turkey3
Scratcher
1000+ posts

Switch Statement

P.S.: That's JavaScript, not Java.
blob8108
Scratcher
1000+ posts

Switch Statement

turkey3 wrote:

That's JavaScript, not Java.
No, it is Java. The code samples provided look the same in both.
magpie5212
Scratcher
100+ posts

Switch Statement

It's a good way to clarify program structure.
Gaza101
Scratcher
500+ posts

Switch Statement

-Io-
Scratcher
1000+ posts

Switch Statement

Gaza101 wrote:

Duplicate.
So, you necroposted to inform of a older topic suggesting the same thing when it had already been informed in the first (second) post (with an even older topic in that post)?

PH-zero wrote:

I already suggested this here: http://scratch.mit.edu/discuss/topic/20351/
support
Gaza101
Scratcher
500+ posts

Switch Statement

-Io- wrote:

Gaza101 wrote:

Duplicate.
So, you necroposted to inform of a older topic suggesting the same thing when it had already been informed in the first (second) post (with an even older topic in that post)?

PH-zero wrote:

I already suggested this here: http://scratch.mit.edu/discuss/topic/20351/
support
Just noticed the necropost. Whoops…

Powered by DjangoBB