Main Content

Number of Return Statements

Number of return statements in a function

Description

This metric measures the number of return statements in a function.

The recommended upper limit for this metric is 1. If one return statement is present, when reading the code, you can easily identify what the function returns.

To enforce limits on metrics, see Compute Code Complexity Metrics Using Polyspace.

Examples

expand all

int getSign (int arg) {
    if(arg <0)
        return -1;
    else if(arg > 0)
        return 1;
    return 0;
}

In this example, getSign has 3 return statements.

Metric Information

Group: Function
Acronym: RETURN
HIS Metric: Yes