Discuss Scratch
- Discussion Forums
- » Suggestions
- » Switch Statement
- Gigabyte_Giant
-
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
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
- blob8108
-
1000+ posts
Switch Statement
No, it is Java. The code samples provided look the same in both. That's JavaScript, not Java.
- -Io-
-
1000+ posts
Switch Statement
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)?

http://scratch.mit.edu/discuss/topic/20351/I already suggested this here:
support
- Gaza101
-
500+ posts
Switch Statement
Just noticed the necropost. Whoops…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)?http://scratch.mit.edu/discuss/topic/20351/I already suggested this here:
support
- Discussion Forums
- » Suggestions
-
» Switch Statement