Question: I am wondering if using LOC and cyclomatic-complexity metrics can anyone draw any conclusions about the relative complexity of the two codes below? is kinda doing my head in.

Code A

```
 int i = 1;
    while(i < = 5){

    playACard(i);

    if (playerHasWon(i))
    break;
    i++
    }

```

Code B

```
int j = 0;

int i = 2;

j = i;
j = j + i;

j++;
System.out.println (j);

System.out.println

```

Answer: 
Using advanced LOC tools (i.e. my eyes and fingers :-) ) I calculate the LOC counts for the two pieces of code are the same ... ignoring blank lines.

For a cyclometric complexity count, you need parseable source code ... in some programming language ... for tools to work. I defer to @d'alar'cop 's answer for a hand calculation and the explanation of how he arrived at it.

---

But to be honest, LOC and Cyclometric Complexity measures for code like this is not helpful. The two samples do completely different things, so it really makes little difference which is more "complex".

To my mind, CC is only really useful for identifying excessively complex code in a first-pass review of a codebase. Once you've identified the problem *areas*, an experienced programmer is a better judge of real complexity (i.e. the kind of stuff that makes the code hard to understand) ... and whether that complexity is necessary / inherent in the problem at hand.
Code B has cyclomatic complexity of 1.
There is *only* 1 possible path through the code. 

Cyclomatic complexity measures the number of possible paths of execution (this is useful in testing and size estimations of a software system.) - but most people would say it's not accurate or useful for the latter.

Code A has cyclomatic complexity of 4. As the code can either enter the loop or not enter it (same as leaving it) (2 possible paths) and there is one 'if statement' which multiplies the possibilities by 2 again.

Cheers.

Any more explanation required?