TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  CFL#014Checked automatically with code checker

Synopsis:Do not return from unexpected locations
Severity Level:9
Category:Control Flow


It is harder to understand a function if, reading it at the bottom, you are unaware of the possibility that it returned somewhere above. So multiple returns in a function should be avoided, if possible. However, in some situations it is perfectly legal to have extra returns. Examples are:

  • precondition checks that fail at the beginning of a function
  • loops that should terminate as soon as some condition is met (e.g. return the first element larger than 10 in a list)