1

For example I got a code:

int a = 3;

if(a < 0)
{
    System.out.println(“a < 0");
}
else if (a == 0)
{
    System.out.println(“a == 0");
}
else
{
    do{
        System.out.println(“Loop never end");
    }while(true)
}
return a;

Cyclomatic complexity I calculated is 4. But I can only find 3 independent path since there only one independent path throw do while, what's wrong?

user3489985
  • 327
  • 4
  • 18

1 Answers1

1

You start with 1. First if increases it to 2. Second if increases it to 3. The while(condition) increases it to 4. A simplified explanation: CC metric gives you an upper limit of possible execution paths, the calculation doesn't take into account the fact that the condition in the while-loop is always true.

Rudolf FERENC
  • 289
  • 1
  • 6