Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert If Statement into Switch

I have this If statement and I would like to move them into Case-Switch

Here is my if Stataments:

if (rResponse.ErrorCode[0] == 0x20 && rResponse.ErrorCode[1] == 0x03)
    ErrorMsg = "COMM_FRAME_ERROR";
if (rResponse.ErrorCode[0] == 0x20 && rResponse.ErrorCode[1] == 0x04)
    ErrorMsg = "JAM";
if (rResponse.ErrorCode[0] == 0x20 && rResponse.ErrorCode[1] == 0x05)
    ErrorMsg = "NO_CARD";

How can I do that?

like image 542
Alexandera MacQueen Avatar asked Sep 01 '26 06:09

Alexandera MacQueen


1 Answers

if (rResponse.ErrorCode[0] == 0x20) {
  switch(rResponse.ErrorCode[1]) {
    case 0x03:
      ErrorMsg = "COMM_FRAME_ERROR";
      break;
    case 0x04:
      ErrorMsg = "JAM";
      break;
    case 0x05:
      ErrorMsg = "NO_CARD";
      break;
  }
}
like image 173
Itay Karo Avatar answered Sep 02 '26 20:09

Itay Karo