Loop exit expression is invariant

The exit condition in a "while" loop is loop-invariant.

A loop invariant expression is one that does not change as the loop executes. Typically, it is an error for a loop condition to be loop invariant. If the loop condition is false, then the loop will execute zero times. Otherwise, the loop condition will never become false and the loop will execute forever. This usually indicates a coding error.

ID

Observation

Description

1

Memory read

The location of the loop with the invariant condition

Example

          
#include <stdlib.h>
#include <stdio.h>

int main (int argc, char **argv)
{
    int j, k, n;

    k = rand();
    n = rand();
    for (j = 0; k == n; j++) {
        printf("%d\n", j);
    }
    return 0;
}
        

Copyright © 2010, Intel Corporation. All rights reserved.