scitools.com

← Metric catalog

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

Statements

API ID: CountStmt
Languages: Ada, Assembly, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, VHDL, Web
Targets: Architectures, Classes, Files, Functions, Modules, Packages, Project, Subprograms

Number of statements.

A single physical line can contain more than one statement, and each clause of a for loop's header (initialization, condition, and increment) counts as its own statement, in addition to its body.

For example:


int main() {
  for (int i = 0;
       i < 10;
       i++)
    ;

  int j = func();
  int k = 0;
  int l = 1;

  int m
    = func();
  int n;
  n = 1;

#ifdef A_VERY_NICE_VARIABLE

  int j = 0;
  cout << j << endl;
#endif

  return 0;
}

main() contains 11 statements: the for loop's three header clauses (int i = 0, i < 10, i++) plus its empty body (;), the six variable declarations and assignments (int j = func();, int k = 0;, int l = 1;, int m = func();, int n;, n = 1;), and the final return 0;, for CountStmt = 11. The two statements inside the inactive #ifdef block don't count.

See Declarative Statements, Executable Statements, and Empty Statements for a breakdown by statement type, and Semicolons for the related count of ; tokens.


Targets By Language: Configuration: