0

Having read McCabe's article about cyclomatic complexity, it reads:

A less frequently occurring issue that has greater impact on complexity is the distinction between “case-labeled statements” and “case labels.” When several case labels apply to the same program statement, this is modeled as a single decision outcome edge in the control flow graph, adding one to complexity.

I do not understand - what is a "case labeled statement" and "case label"?

Do they mean if case 1, case 2, e.g. both jump to case 3?

jaco0646
  • 15,303
  • 7
  • 59
  • 83
Pietross
  • 313
  • 1
  • 3
  • 9

1 Answers1

1

Yes, McCabe is pointing out the difference in complexity between a case that directly labels a statement and a case that falls through to another case.

Each "case-labeled statement" adds to cyclomatic complexity, so the following example adds +3.

switch (arg) {
    case "foo" : System.out.println("foo");
    case "bar" : System.out.println("bar");
    case "baz" : System.out.println("baz");
}

A "case label" which falls through to another case does not add to cyclomatic complexity, so the following example adds +1.

switch (arg) {
    case "foo" :
    case "bar" :
    case "baz" : System.out.println("foo | bar | baz");
}
jaco0646
  • 15,303
  • 7
  • 59
  • 83