/** * A collection of methods that use Java's looping mechanisms. * * @author Samuel A. Rebelsky * @version 1.0 of August 1998 */ public class WhileExamples { /** * Print the numbers from 1 to n */ public void countTo(int n, SimpleOutput out) { int i = 1; while (i < n) { out.println(i); i = i + 1; } // while } // countTo(int n, SimpleOutput out) /** * Keep reading passwords until you read the supplied password. */ public void readPass(SimpleInput in, SimpleOutput out, String pass) { String name = ""; while (!name.equals(pass)) { out.print("Enter the password: "); name = in.readString(); // If the password was entered correctly, the loop // should terminate. out.println("'" + name + "' was not a valid password."); } // while } // readPass(SimpleInput, SimpleOutput, pass) } // class WhileExamples