scitools.com

← Metric catalog

Exits is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Exits

API ID: CountExit
Languages: Any
Targets: Functions

The number of explicit exits/returns from a function

Example:

    void none() { }           // CountExit = 0
    void one() { return; }    // CountExit = 1
    int two(int x)
    {
      if (x > 0)
        return x;             // +1
      return -x;              // +1
    }                         // CountExit = 2

    void otherExits(int x)
    {
      if (x > 0)
        goto label;           // +1 goto counts as exit
      else
        return;               // +1

    #if 0
      return;                 // inactive code does not count
    #endif

    label:
      return;                 // +1
    }                         // CountExit = 3
    

See also CountEarlyExit.