There are 2 sets of key words that can potentially do the same thing - switch/case and if/else. Question is, which is the better method to use for something like this?
Both methods accomplish exactly the same effect so what is the difference? Performance (aka faster to process)? Readability? Something else?Code:unsigned int CaseID; ... // compare this switch(CaseID) { case 1: // do stuff if the "CaseID" variable is 1 break; case 2: // do stuff if the "CaseID" variable is 2 break; default: // do stuff if the "CaseID" variable is anything else } // to this if (CaseID == 1) { // do stuff if the "CaseID" variable is 1 } else if (CaseID == 2) { // do stuff if the "CaseID" variable is 2 } else { // do stuff if the "CaseID" variable is anything else }