Jtest logo




Contents  Previous  Next  Index

MISC.PIF


Provide an incremental segment/part in a "for" loop or use a "while" loop

Description

This rule flags any "for" statement that does not have an incremental part.

This may be an indication that the incremental part is missing or that the code would be clearer if a "while" statement were used instead of a "for" statement.

Example

 package MISC;
 
 public class PIF {
     void method () {
         int i = 0;
         for (; i < 1000; ) {
             if (i % 2 == 0) {
                 i = 2 * i + 1;
             } else {
                 i = i/2;
             }
         }
     }
 }

Repair

Check if the third argument of the "for" statement is missing. If it is missing, either increment the counter within the "for" structure or change the "for" statement to a "while" statement.


Contents  Previous  Next  Index

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