Method calls can be used instead of literals comparisons:

public class ForLoopsMethodCalls {
       public static void main(String [] arg){         
             for (int x = intValue(); test(x); x = go (x)){
                  System. out .println(x);
            }                 
      }
      
       public static Boolean test(int x){
             return new Boolean(x < 10);         
      }
      
       public static int intValue(){
             return 0;
      }
      
       public static int go(int x){
             return ++x;
      }           
}

Wrapper objects can be used where literals are used:

public class ForLoopsWrapperClasses {
       public static void main(String [] arg){         
             for (int x = Integer.valueOf(10); test(x); x = go(x)){
                  System.out.println(x);
            }           
      }
      
       public static Boolean test(int x){
             return new Boolean(x < 10);         
      }
      
       public static Integer go(int x){
             return new Integer(3);
      }                 
}

Leave a comment