# Control Flow Graphs – Georgia Tech – Software Development Process Let’s look at the code for PrintSum in a slightly different way by making something explicit. If we go through the code, we can see that the, the code does something in that case, if the result greater then zero, does something else if the result is not greater than zero but is less than zero, and otherwise in the case in which neither of these two conditions is true. Nothing really happens. So we’re going to make that explicit, we’re going to say here, otherwise do nothing, which is exactly our problem, the code does nothing, in this case where it should do something. So now, let’s look again in our test cases, let’s consider the first one, and I’m going to go a little faster in this case, because we already saw what happens If we execute the first test case, we get to this point, we execute this statement, and then we just jump to the end, as we saw. Now we, if we execute the second test case, we do the same, we get to the else statement, the condition for the if is true, and therefore we execute this statement. And we never reached this point for either of the test cases. So how can we express this? In order to do that, I’m going to introduce a very useful concept. The concept of control flow graphs. The control flow graphs is just a representation for the code that is very convenient when we run our reason about the code and its structure. And it’s a fairly simple one that represents statement with notes and the flow of control within the code with edges. So here’s an example of control flow graph for this code. There is the entry point of the code right here, then our statement in which we assign the result of A plus B to variable result. Our if statement and as you can see the if statement it’s got two branches coming out of it, because based on the outcome of this predicate we will go one way or the other. In fact normally what we do, we will label this edges accordingly. So for example, here we will say that this is the label to be executed when the predicate is true. And this is the label that is executed when the predicate is false. Now, at this point, similar thing, statement five which corresponds with this one, we have another if statement and if that statement is true, then we get to this point and if it’s false, we get to this point. So as you can see, this graph represents my code, in a much more intuitive way, because I can see right away where the control flows, while I execute the code. So we’re going to use this representation to introduce further coverage criteria.

### 8 thoughts on “Control Flow Graphs – Georgia Tech – Software Development Process”

• lucksy bb says:

thank you!

• Engineering says:

#EEE

• Frankie McDonagh says:

• Dave Howson says:

Cannot understand anything you say because of that weird accent of yours

• Sophia Price says:

Spent ages looking for a simple explanation, this is great! Just one question. Would a declaration of a variable be a step in the control flow graph? i.e: int result; << on it's own ?

• Swaraj Behera says:

Thanks buddy !!

• Zainab Amin says:

Label the nodes with statements numbers

• Nguyen Hanh Phuc says:

Is there any tool or program (source code) from C/C++/Java program to CFG? Thank you.