What is a control flow path?

A control flow path (or control flow graph) is a graphical representation of the flow of a program.

Control flow paths represent all of the paths we can traverse during the execution of a program.

We use control flow paths most frequently for the white box testing of software.

Properties

A control flow graph is a directed graph.

A control flow graph consists of two designated blocks:

  1. Entry block
  2. Exit block

As their names suggest, these blocks direct the entry and exit of the control flow into and out of the graph.

Decision point

A decision point is a point in the control flow graph where the control of the program diverges. Common examples include do-while statements, if statements, and case statements.

These statements are also referred to as control flow statements.

A decision point in a CFG

Example

We can better understand control flow paths by making one of our own.

Consider the following program:

#include <iostream>
using namespace std;
int main(){
int a[100] = {0};
for(int i = 0; i < 100; i++)
a[i] = i;
int temp;
int x = 0;
while (x < 100)
{
if (a[x] % 2 == 0)
temp = 0;
else
temp = 1;
switch (temp)
{
case 0: cout << "a["<<x<<"] is even\n"; break;
case 1: cout << "a["<<x<<"] is odd\n"; break;
default: cout << "unexpected error\n";
}
x++;
}
return 0;
}

The above program declares and populates an array of size 100. Then, we check each array element to determine whether it is even or odd.

Based on that, we set the value of temp (0 for even, 1 for odd).

For each element, the switch statement runs the case based on the value of temp.

Finally, the value for x is incremented after breaking out of the switch statement.

The control flow graph for the program is as follows:

CFG for the above code

The following is the breakdown of the control flow graph above:

  1. The start of the while loop

  2. The if statement

  3. The branch we take if the if condition is true

  4. The else statement

  5. The switch statement

  6. case 0 statement

  7. case 1 statement

  8. default statement

  9. Increment (x++)

  10. return statement

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved