// F O R  used when you know the
// maximum number of times to iterate in advance.
// Note lack of; after i++
for ( int i=0; i<n; i++ )
   {
   System.out.println( i );
   }

// R E V E R S E   F O R  to countdown
for ( int i=n-1; i>=0; i-- )
   {
   System.out.println( i );
   }

// D U A L   F O R
// Note lack of; after j++
for ( int i=0, j=0; i<n; i++,j++ )
   {
   System.out.println( i );
   }
// However, this is illegal!
for ( int i=0, float r=1.0; i<n; i ++ ,r=r*2.0 )
   {
   System.out.println( i );
   }

// A R R A Y - S P A N N I N G   F O R
String[] stuff = new String[ 10 );
for ( int i=0; i<n; i++ )
   {
   String s = stuff[i];
   System.out.println( s );
   }

// A R R A Y - S P A N N I N G   F O R   Java 1.5+
// works when stuff is an array, ArrayList or Collection,
String[] stuff = new String[ 10 );
...
for ( String s : stuff )  // note String not int!!
   {
   System.out.println( s );
   }

// E N U M - S P A N N I N G   F O R   Java 1.5+
// Example iterating over all possibilities.
// Print out a list of all possible breeds of Dog
enum Breed { DALMATIAN, LABRADOR, DACHSHUND }
...
for ( Breed dog : Breed.values() )
   {
   System.out.println( dog );
   }

// E N U M E R A T I O N
// (nothing to do with enum)
// (largely replaced by Iterator)
// Note; after hasMoreElements().
for ( Enumeration e = props.propertyNames(); e.hasMoreElements(); )
   {
   String key = (String) e.nextElement();
   System.out.println( key );
   }

// I T E R A T O R
// Note; after hasNext()
for ( Iterator iter = list.iterator(); iter.hasNext(); )
   {
   String key = (String)iter.next();
   System.out.println( key );
   }

// I T E R A T O R : alternate when you already have the Iterator
Iterator someFiles = getFilesToProcess();
while ( someFiles.hasNext() )
   {
   File f = (File)someFiles.next();
   ...
   }

// I T E R A T O R - R E M O V E :  efficiently removing elements from a List (ArrayList, LinkedList etc.)
// or Collection.
// You can't remove elements with a for:each.
// This works faster than a get/remove.
// This approach avoids the effects of the List renumbering as you go which can cause you to
// inadvertently skip elements or run off the end.
for ( Iterator<Item> iter = items.iterator(); iter.hasNext(); )
   {
   Item item = iter.next();
   if ( item.isUnwanted() )
       {
       // remove from underlying Collection
       iter.remove();
       }
    }

// I T E R A B L E : Java 1.5+
// myFiles is a refererence to a container class that implements Iterable,
// namely has an iterator() method to enumerate the
// elements of the collection.
// All Collections such as ArrayList, TreeSet,
// HashMap, PriorityQueue... all implement Iterable.
// Note what you use in the for:each
// is not the result of myFiles.iterator() but myFiles itself.
// Note for, not while
for ( File f : myFiles )
   {
   if ( f.isDirectory() ) ...
   }

// I T E R A B L E  W I T H   E L L I P S I S (...): Java 1.5+

void myMethod( String... animals )
   {
   for ( String animal : animals )
      {
      System.out.println( animal );
      }
   }

// calling myMethod
myMethod( "tiger", "lion", "hippopotamus" );
myMethod( "tiger" );
myMethod( );
String[] someStringArray = getValues();
myMethod( someStringArray );

// W H I L E  (loop possibly zero times)
// Used when you don't know in advance how many times max you will loop.
while ( moreData() )
   {
   readIt();
   }

// D O / W H I L E  (loop at least once)
// Used when you don't know in advance how many times max you will loop.
do
   {
   readIt();

   if ( done() )
      {
      break;
      }

   if ( bypassThisOne() )
      {
      continue;
      }

   processIt();

   } while ( moreData() );
// -30-