public void Switch(){
var a = 100;
switch (a){
case 1:
Debug.Log ("1");
break;
case 2:
Debug.Log ("2");
break;
}
.
.
.
case 100:
Debug.Log ("100");
break;
}
}
my question is that, if I set a to 100 ,it will access to case 100 directly ???
Yes, that’s how switch works.
Unless you meant whether it will check every case until it reaches 100, in which case no (not “directly”, that is).
It will check every case until case 100, but only case 100 will execute because of break; calls.
1 Like
thanks for response,so what’s the difference between switch and else if ?
Different compiled code. Subtle speed differences depending on number of cases. Nothing to be worried about unless it impacts performance. But you would need a lot of cases for that.
1 Like