[previous] 0771 [next] More than one 'break' statement has been used to terminate this iteration statement.
Control flow

More than one break statement has been used to terminate an iteration statement, i.e. a while, do ... while or for statement. If multiple break statements are used within the same iteration statement, the code can become dangerously unstructured.

For example:


/*PRQA S 2017,3408,3447 ++*/


extern int x;
extern int y;
extern int z;

extern void foo(int n)
{
    while (n > 0)
    {
        --n;
        if (n == x)
        {
            break;                      /* Message 0769 */
        }
        if (n == y)
        {
            break;                      /* Message 0771 */
        }
        if (n == z)
        {
            break;                      /* Message 0771 */
        }
    }
}


MISRA C:2012 Rules applicable to message 0771:

Rule-15.4  (Advisory) There should be no more than one break or goto statement used to terminate any iteration statement


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents