<p>I was wondering if there was any difference in the way the following code was compiled into assembly. I've heard that switch-case is more efficient than if else, but in this example I am not quite sure if that would be the case.</p>

<pre><code>if(x==1){
...
}else if(x==2){
...
}else{
...
}
</code></pre>

<p>and</p>

<pre><code>switch(x){
 case 1:
 ...
 break;

 case 2:
 ...
 break;

 default:
 ...
}
</code></pre>

In
this
specific case, the
```
switch
```
can be turned into a jump table. The
```
if
```
statement (if you write your
```
=
```
as
```
==
```
:-P) could still do the same thing if the compiler could tell that
```
x
```
isn't changing between the
```
if
```
clauses (which is usually the case, unless
```
x
```
is
```
volatile
```
or something).