Very basic 'switch' question

Hi, I haven’t posted on here before so sorry if it’s the wrong place or too basic.

So I am doing a basic switch operation and am trying to +1 for a ‘case’ why does the first example work but the second doesn’t? I imagine it is basic. Can i not use +1;? I also tried = +1;

switch(var){
case 2:
count++;
break;

switch(card){
case 2:
count +1;
break;

This:

count++;

changes the variable count. It increases it by 1.

This:

count +1;

does not change the variable count. It evaluates to count + 1. But in your code, it does nothing with that result. You could do count = count + 1 and that would have the effect you are expecting.

2 Likes

Thank you for the response, that has helped me make much more sense of it.