Switch Statement

A feature I’d like to see in Hopscotch is:

Switch Statements

I’d use it for this type of project:

for making individual clones do different things, variable cases, it makes it easy to understand and look back on

Here are some examples of Hopscotch code that could be improved if we had this:

Here is an example design I’ve made:


sorry for extremely horrible photoshop

I’ve seen something similar in another programming language, it looks like this:

Swift
JavaScript
looks like:

switch x {
  case -1:
    alert(“OBEY ME PUNY MORTALS”);
  break;
  case 2:
    alert(“PUNY MORTALS OF +2 NOT OBEYING”);
  break;
  default:
    alert(“JOIN -1 AND OBEY ME PUNY MORTALS”);
}

pretty sure this is how it looks


  • yes
  • no
  • eh

0 voters

13 Likes

Cool!

I think this could simplify things immensely.

Lol and I got first post.

4 Likes

This is a great idea
Lol yes this is extremely frustrating

4 Likes

I don’t understand lol

3 Likes

I’m a coding wizard, or at least what my friends call me, and I too don’t understand.

4 Likes

Isn’t this like the check if else statement?

2 Likes

instead of having a bunch of check once ifs, this has “cases” where if (x) = 1 it does something or if x = 3 it does another thing

this:
check if x = 4 {
destroy
} else {
check if x = 5 {
destroy
}
} else {
grow by 10
}

could look like this:

switch x {
case 4:
destroy
break;
case 5:
destroy
break;
default:
grow by 10
}

default is basically “if none of the cases are true”

6 Likes

So basically it’s a check if else but it doesn’t get messy when there’s too many?

2 Likes

ok I guesss that could make things simpler

2 Likes

Same. Lol.

3 Likes

kind of. it’s like it, but much easier to understand in mass amounts

3 Likes

Great idea!
we definitely need this.

5 Likes

for sure like if one has a lot of if else statement

2 Likes

yes, because I could hardly understand some of our summer comp draft with the check once ifs lol, with switch also you wouldn’t have to worry about not being able to see the full number in case of too many check ifs

3 Likes

So it’s basically the same thing as a bunch of check if else’s except it doesn’t leave your code looking like this?

5 Likes

Yes true lol our draft has waayyy too many checks

4 Likes

this looks cool!

4 Likes

Nice idea!

4 Likes

yes

2 Likes

And this is why I can’t understand the majority of the parts I didn’t code.

4 Likes