scitools.com

← Metric catalog

Early 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.

Early Exits

API IDCountEarlyExit
TargetsFunctions
LanguagesAny
SolutionHersteller Initiative Software (HIS)
CategoriesStatements
CostQuery

The number of explicit exits/returns from a function excluding the final statement

Also known as Hersteller Initiative Software (HIS) RETURN metric.

Example:

    void none() { }           // CountEarlyExit = 0
    void one() { return; }    // CountEarlyExit = 0, return is the last statement
    int two(int x)
    {
      if (x > 0)
        return x;             // +1
      return -x;              // return is the last statement
    }                         // CountEarlyExit = 1

    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;                 // return is the last statement
    }                         // CountEarlyExit = 2
    

See also CountExit.