Main Content

AUTOSAR C++14 Rule M6-6-3

The continue statement shall only be used within a well-formed for loop

Description

Rule Definition

The continue statement shall only be used within a well-formed for loop.

Rationale

Using a continue statement can add unnecessary complexity to code, which can cause issues during testing due to the additional logic required.

Polyspace Implementation

The rule checker reports a violation for the use of continue statements in:

  • for loops that are not well-formed, that is, for loops that violate rules 6-5-x

  • while loops

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

The for loop in this code is not well-formed as it breaks MISRA C++:2008 Rule 6-5-2. Because the for loop in the example is not well-formed and contains a continue statement, Polyspace raises this violation.

#include <cstdint>

uint32_t row, col;

void example()
{
    for (row = 0; row <= 10; row++) {
        for (col = 100; col != 10; col -= 4) {
            //...
			continue;		//Noncompliant
        }
    }
}

Check Information

Group: Statements
Category: Required, Automated

Version History

Introduced in R2019a