I am having some trouble and could use some help. I need a while loo that allows for an unlimited number of employees that uses a EOF sentinal value to control the loop. heres what I have so far, any help is greatly appreciated. I really dont understand this type of loop very well.

System.out.println(" Do you want to enter information ?");
String choose = input.nextLine();
System.out.println(" What is your name ? ");
String name = input.nextLine();
System.out.println(" What is your age ?");
String age = input.nextLine();
System.out.println(" What is your ssn ?");
String ssn = input.nextLine();
System.out.println(" What is your address ?");
String address = input.nextLine();
System.out.println(" Do you wish to make another entry ?");


while( = "yes");
{.

close, you need to make the loop go outside of all that, also please place code in code tags

System.out.println(" Do you want to enter information ?");
String choose = input.nextLine();

while(choose.equals("yes")) {
System.out.println(" What is your name ? ");
String name = input.nextLine();

System.out.println(" What is your age ?");
String age = input.nextLine();

System.out.println(" What is your ssn ?");
String ssn = input.nextLine();

System.out.println(" What is your address ?");
String address = input.nextLine();

System.out.println(" Do you wish to make another entry ?");
choose = input.nextLine();
}

Thanks for your help I really appreciate it. Carl

Sure thing, always show your effort and we will be more than willing to help

Thanks so much that worked great. I am new to java and that loop was starting to fry my brain. I need to spend some more time on them. Thanks again

here's a tip

use while loops when you don't know the number of iterations (you never know when the user will type "no")

use a for loop for a known size
(for each hour in the day, have 5 records)

> use a for loop for a known size

Not necessary; while loops can be completely avoided. A `for' loop can easily replace a `while' and `do while' looping constructs.

// while equivalent
String line = null;
for( ; (line = reader.readLine()) != null; ) {
  // process the line read
}

// do..while equivalent
boolean keepGoing = true;
for( ; keepGoing; ) {
  // do some processing
  if(reply.equals("quit")) {
    keepGoing = false;
  }
}

@carlcarman: Consider using code tags the next time you post code snippets.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.