MISRAC++2008-6-6-4
In this section:
Synopsis
(Required) For any iteration statement there shall be no more than one break or goto statement used for loop termination.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
One or more loops have more than one termination point. This check is identical to MISRAC2012-Rule-15.4.
Coding standards
- MISRA C:2012 Rule-15.4
(Advisory) There should be no more than one break or goto statement used to terminate any iteration statement
- MISRA C++ 2008 6-6-4
(Required) For any iteration statement there shall be no more than one break or goto statement used for loop termination.
Code examples
The following code example fails the check and will give a warning:
int test1(int);
int test2(int);
void example(void)
{
int i = 0;
for (i = 0; i < 10; i++) {
if (test1(i)) {
break;
} else if (test2(i)) {
break;
}
}
}
void func()
{
int x = 1;
for ( int i = 0; i < 10; i++ )
{
if ( x )
{
break;
}
else if ( i )
{
break; // Non-compliant – second jump from loop
}
else
{
// Code
}
}
}
The following code example passes the check and will not give a warning about this issue:
void example(void)
{
int i = 0;
for (i = 0; i < 10 && i != 9; i++) {
if (i == 9) {
break;
}
}
}
void func()
{
int x = 1;
for ( int i = 0; i < 10; i++ )
{
if ( x )
{
break;
}
else if ( i )
{
while ( true )
{
if ( x )
{
break;
}
do
{
break;
}
while(true);
}
}
else
{
}
}
}