// for each loop gotchas

// In Java 1.5+ you can write a for each loop
// over an array or iterable collection

String[] mystrings = new String[ 50 ];

for ( String s : mystrings )
   {
   out.println ( s );
   }

// This is shorthand for:

for ( int i=0; i<mystrings.length; i++ )
   {
   out.println ( mystrings[i] );
   }

// However the following code won't compile
// because String is not iterable

String mystring = "happy birthday";

for ( char c : mystring )
   {
   out.println ( c );
   }

// you have to write it out longhand

for ( int i=0; i<mystring.length; i++ )
   {
   out.println ( mystring.charAt( i ) );
   }

// or use a char[] instead of String

String mystring = "happy birthday";
char[] chars = mystring.toCharArray();

for ( char c : chars )
   {
   out.println ( c );
   }

// Further the following code will not compile

String[] mystrings = new String[ 50 ];

for ( int i : mystrings )
   {
   out.println ( mystrings[i] );
   }

// you have to write it out longhand

for ( int i=0; i<mystrings.length; i++ )
   {
   out.println ( mystrings[i] );
   }