import java.io.*;
/* Read and process loops:
   Keep reading input until a particular input is encountered
   Has the following form

   String s;
   Read the first input into s
   // Invariant: have processed lines before s, s is NEXT TO BE PROCESSED
   while(s is not the stopping input){
      Process s
      Read the next input into s
   }

   This is really just like the counting while loops
   seen previously (ie)
   int k=0;
   // Invariant: have processed 0,...,k-1, k is NEXT TO BE PROCESSED
   while(k<n){
      Process k
      k=k+1
   }

   Note: An Invariant is a true statement about the state of variables (etc.)
   evaluated at the associated loop guard. That is, each time the loop guard
   is visited, the Invariant must be true. Invariants are good documentation.
*/

class ProcessFile{
	public static void main(String args[]) throws Exception{
		processFile1("SomeText.txt");
		processFile2("SomeText.txt");
	}

	// Process each line of a file
	public static void processFile1(String fileName) throws Exception{
		FileReader fr=new FileReader(fileName);
		BufferedReader br=new BufferedReader(fr);

		String line; 

		line=br.readLine(); // readLine returns null when file is exhausted
		//Inv: line is the next line of text from fileName TO BE PROCESSED
		while(line!=null){
			System.out.println(line); // Process
			line=br.readLine(); 
		}
	}

	// Process each line of a file (alternate form)
	public static void processFile2(String fileName) throws Exception{
		FileReader fr=new FileReader(fileName);
		BufferedReader br=new BufferedReader(fr);
		String line; 

		//Inv: line is last line of text from fileName that WAS PROCESSED
		while(true){
			line=br.readLine();
			if(line==null)break; // immediately leave THIS loop
			System.out.println(line); // Process
		}
	}
}
