Main Content

Number of Return Statements

Number of return statements in a function

Description

Note

Use Bug Finder instead of Code Prover for computing code metrics. Support for computing code metrics in Code Prover will be removed in a future release. See Version History.

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

Version History

expand all