// Need this import for reading data:
import java.io.*;

// reading data in a loop until a specific command
public class WhileInput {

    public static void main (String [] args) throws IOException {
	// Create a buffered reader
	BufferedReader in = new BufferedReader(
			new InputStreamReader(System.in));
	// string for storing a line of input
	String line = new String();

	System.out.print("Please say something. Say \"bye\" to end. ");
	line = in.readLine();
	while (! line.equalsIgnoreCase("bye")) {
	    System.out.println("You said: " + line);
	    System.out.print("Keep on talking. Say \"bye\" to end. ");
	    line = in.readLine();
	}
	System.out.println("Nice talking with you! See you later...");
    }

}

This is an example from CSci 1211 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.