//:::::::::::::::::::::::::::::::::::::::::::::
/** @author   Casey Bowman
 *  @version  1.1
 *  @date     Sat Feb 28 11:47:41 EST 2015
 *  @see      LICENSE (MIT style license file).
 */

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** A class to show how to use for loops to iterate through an
 *  integer array.
 */
public class SimpleForLoop
{
    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    /** main method.  Creates a new integer array initialized with
     *  zeros and prints it.  Then, it sets the elements using a 
     *  formula, and prints the array again.
     */
    public static void main (String[] args)
    {
        int[] t = new int[10];
        
        print (t, "t");

        for (int i = 0; i < t.length; i++) { t[i] = i * 10 + 1; }   // a for loop with a single execution statement can be concisely written on a single line.
    
        print (t, "t");

    } // main
 
    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    /** Print an integer array in the style " = Array [1, 2, 3, 4]"
     *  @param t     the integer array to print
     *  @param name  the name of the array
     */
    public static void print (int[] t, String name)
    {
        System.out.print (name + " = Array [");
        for (int i = 0; i < t.length; i++)
        {
            if (i < t.length - 1) 
                System.out.print (t[i] + ", ");
            else 
                System.out.println (t[i] + "]");
        }
    } // print

} // SimpleForLoop