import java.io.*;

/**
 * An example that illustrates different ways of reading from a stream
 * until the end-of-stream is encountered.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class EndOfStreamExample
{
    /**
     * The entry point of the example.
     *
     * @param args  The command-line arguments (which are ignored)
     */
    public static void main(String[] args)
    {
        BufferedReader   in;        
        String           line;
        
        in = new BufferedReader(new InputStreamReader(System.in));

//[while
        // Read the first line
        try
        {
            line = in.readLine();
            while (line != null)
            {
                // Process the input
                
                // Read subsequent lines
                line = in.readLine();
            }
        }
        catch (IOException ioe)
        {
            // Handle the exception
        }
    
//]while

//[do
        try
        {
            do
            {
                // Read a line
                line = in.readLine();
                
                if (line != null)
                {
                    // Process the input
                }
            } while (line != null);
        }
        catch (IOException ioe)
        {
            // Handle the exception
        }
//]do


//[elegant
        try
        {
            while ((line = in.readLine()) != null)
            {
                // Process the line
            }
        }
        catch (IOException ioe)
        {
            // Handle the exception
        }
//]elegant

    }
    
}
