0
if (k =  = 1) 
        r  +  =  a;
else if (k =  = 2) 
        r  +  =  b;
else if (k =  = 3) 
        r  +  =  c;
else  
        r  +  =  d;


switch (k) {
    case 1:
    r   +  =  a;
    break;
    case 2:
    r   +  =  b;
    break;
    case 3:
    r   +  =  c;
    break;
    default:
    r   +  =  d;
    break;
    }

I am trying to understand whether for both the multiple if statement and the switch case the sample control flow diagram is the below diagram. I am sure that it is true for the switch case but i am unable to draw one for the multiple if statement

Control flow grpah

George Silva
  • 385
  • 5
  • 13

1 Answers1

2

The switch statement is nothing but syntactic sugar for the multiple if/else. The control flows are exactly the same. So is the cyclomatic complexity.

Frank Puffer
  • 8,135
  • 2
  • 20
  • 45