Jtest logo




Contents  Previous  Next  Index

MISC.PCF


Provide a condition in a "for" loop

Description

This rule flags any "for" loop that does not have condition.

Failing to provide a condition in a "for" loop might cause infinite loops.

Example

The following example shows a "for" statement that has an empty second slot. This might cause infinite loops.

 
 package MISC;
 
 public class PCF {
     void method () {
         int i = 0;
         int j = 0;
         for (;; i++) {
             j++;
             break;
         }
     }
 }

Repair

Consider providing a condition that will be tested before each new pass through the loop.


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft