import java.util.ArrayList;

/**
 * This class illustrates While loops, in comparison with traditional
 * for loops and foreach loops.
 * 
 * @author Alyce Brady
 * @version 12 February 2016
 */
public class WhileLoopIllustration
{
    /**
     * This main method runs the code in the While Loop Illustration.
     */
    public static void main(String[] args)
    {
        // Construct an ArrayList,
        //   put some values in it,
        //   and step through it.
        ArrayList<Student> studentList = new ArrayList<Student>();
        studentList.add(new Student("Rey Diaz", "CS", 102345));
        studentList.add(new Student("Hermione Granger", "CES", 102678));
        // ... Add more students ...
        
        // Use traditional for loop to print info about each student.
        for ( int i = 0; i < studentList.size(); i++ )
        {
            Student s = studentList.get(i);
            System.out.println(s.getName() + ": " +
                s.getMajor() + " (" + s.getID() + ")");
        }

        // Use foreach loop to print every student's ID and name.
        for ( Student s : studentList )
        {
            System.out.println(s.getID() + ": " + s.getName());
        }

        int i = 0;
        while ( i < studentList.size() )
        {
            Student s = studentList.get(i);
            System.out.println(s.getName() + ": " +
                s.getMajor() + " (" + s.getID() + ")");
            i++;
        } 
        
//         while ( true )
//         {
//             System.out.println("Looping forever...");
//         }

//         while ( (String name = someObj.getName()) != null )
// //         for ( String name = someObj.getName(); name != null;
// //                                                 name = someObj.getName())
//         {
//             // Do something with the next name
//         }
    }

}
