[previous] 2990 [next] The value of this loop controlling expression is always 'true'.
Invariant operations

This message is generated when the controlling expression of an iteration statement (while, do-while or for) is not a constant expression but is nevertheless always non-zero. In other words the expression could simply be replaced by the value "1". The fact that this expression is "degenerate" suggests a logical flaw in the code, for example a control variable not modified within the loop.

For example:


/*PRQA S 2017,2467,3120,3204,3227,3355,3357,3408 ++*/

void f1(int n)
{
    if (n > 0)
    {
        while (n != 0)                /* 2990 2871 */
        {
        }
    }
}

void f2(int n)
{
    if (n > 0)
    {
        do                            /*      2871 */
        {
        } while (n != 0);             /* 2990 2995 */
    }
}

void f3(int n)
{
    int i;

    if (n > 0)
    {
        for (i = 0; i < n; )          /* 2990 2871 */
        {
        }
    }
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents