File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes A looping algorithm question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "A looping algorithm question?" Watch "A looping algorithm question?" New topic
Author

A looping algorithm question?

Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
Hi,
I have the following code:

I instantiated an obj and passed 6 parameters, they were written to a text file with PrintOut method in Write class. Since A to F are private variables, I use get methods to return their values.
So, there is a record of 6 data written to a text file.
However, after saving this record, I want the console to ask whether the user wants to input additional record? e.g. System.out.println("Do you want to add more record (Y/N)?"); and it got the "y/n" reply from user. I know how to use BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); to get user input.

However, I do not know where should I put the while/do...while loop as the logic is:
Ask the user to input the first record;
then
Ask the user whether he wants to add more record for continuing input;
A while loop seems not feasible.
Anyone could propose the algorithm?
Thanks a lot
Andrew
Vin Kris
Ranch Hand

Joined: Jun 17, 2002
Posts: 154
do {} while()
Norm Miller
Ranch Hand

Joined: May 21, 2002
Posts: 56
On the other hand,
Van Rensaleer says that is discouraged.
See 5.1.1 of the Coding standard.
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
You can write any loop using a while loop. for loops can be written as while or do/while. Also, do/whiles can be written as for or while as well.
Just watch your logic


Author and Instructor, my book
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A looping algorithm question?