# Switch vs. if else

**URL:** <https://forum.kirupa.com/t/switch-vs-if-else/238734>\
**Category:** Uncategorized\
**Created:** [September 14, 2007, 12:53pm UTC](https://forum.kirupa.com/t/switch-vs-if-else/238734 "2007-09-14T12:53:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dwight](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@Dwight](https://forum.kirupa.com/u/Dwight)\
**Post date:** [September 14, 2007, 12:53pm UTC](https://forum.kirupa.com/t/switch-vs-if-else/238734/1 "2007-09-14T12:53:03Z")

</div>

Hi peeps,

I’m currently building a Flash Game for my work. I made a switch to check if my items fell into the right bucket. But when I was developing all my other functions I realized that I could handle this in an If Else instead…

So the question is: **What is faster (less CPU intensive), a switch or If Else?**

Here is my switch:

```auto
 
function getPoints(naam,orgNaam,baksoort):Void {
    switch(baksoort){
        case "bak_B01":
            if(naam != "B_01"){
                addBPoints(orgNaam);
            } else {
                addGPoints(orgNaam);
            }
        break;
        
        case "bak_B02":
            if(naam != "B_02"){
                addBPoints(orgNaam);
            } else {
                addGPoints(orgNaam);
            }
        break;
        
        case "bak_B03":
            if(naam != "B_03"){
                addBPoints(orgNaam);
            } else {
                addGPoints(orgNaam);
            }
        break;
        
        case "bak_B04":
            if(naam != "B_04"){
                addBPoints(orgNaam);
            } else {
                addGPoints(orgNaam);
            }
        break;
        
        case "bak_B05":
            if(naam != "B_05"){
                addBPoints(orgNaam);
            } else {
                addGPoints(orgNaam);
            }
        break;
        
        default:
            // doet niets
        break;
    }
}

```

Here is my if else:

```auto

function getPoints(naam,orgNaam,baksoort):Void {    
    if(baksoort == orgNaam) {
        addGPoints(orgNaam);
    } else {
        addBPoints(orgNaam);
    }
}

```

Thanks 👼
