For+Each+Loops

A "For Each" loop is a "shortcut" for a For Loop. It is only useful in arrays and it automatically goes all the way through an array.

__Original Way__ for(int i = 0; i < myList.length; i++)

__For Each Loop__ for( **type of things in the array** variable name **: array name** )


 * iterator is actually the value of the array, not the index value.

ex. for( int iterator : myList ) for( Mii iterator : myMiis )

Example of a code using For Each:

code format="java5" public int countEvens (int[] nums) {  /*    * Go through whole list * Check if the number is even * Add one to my counter */  int count = 0 for( int interator : nums) {     if (interator % 2 == 0) count++; }  return count; } code __**NOTE**__**:** for each loops are rarely used