AUTOSAR C++14 Rule M6-5-4
The loop-counter shall be modified by one of: --, ++, -=n, or +=n; where n remains constant for the duration of the loop
Description
Rule Definition
The loop-counter shall be modified by one of: --, ++, -=n, or +=n; where n remains constant for the duration of the loop.
Rationale
If the loop-counter modifier of the loop is not constant, the loop might end unpredictably, causing results contrary to your expectations. Constant increments create predictable loop termination.
Polyspace Implementation
Polyspace® reports this defect whenever the modifier of a loop-counter is not constant. Polyspace also reports this defect when you modify a loop by -=n or +=n and modify n within the loop.
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
Check Information
Group: Statements |
Category: Required, Automated |