[previous] MISRA-C:2004  Rule  14.6:  (Required) [next] For any iteration statement there shall be at most one break statement used for loop termination.
These rules are in the interests of good structured programming. One break statement is allowed in a loop since this allows, for example, for dual outcome loops or for optimal coding.

Example Code:


#include "misra.h"
#include "m2cmex.h"


extern S16 test_1406( void )
{
   S16 n;

   for ( n = 0; n < 5; n++ )
   {
      if ( n > s16a )
      {
         break;
      }

      switch (s16a)
      {
      case 1:
         ++s16b;
         break;
      case 2:
         if (s16b > s16a)
         {
            break;
         }
         ++s16b;
         break;
      default:
         break;
      }

      if ( n > (s16a - 2) )
      {
         break;               /* MISRA Violation */
      }

   }

   return s16b;
}


QAC messages that encompass this guideline:

0771 More than one 'break' statement has been used to terminate this iteration statement.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents