Skip to content
Sign upLog in
question about while loops
Profile icon

How can I make a while loop only loop once and then ask for user input again? Right now, my while loop goes on forever, but I want it to loop one time, then ask for user input.

You are viewing a single comment. View All
Answered by cuber1515 [earned 5 cycles]
View Answer
Profile icon

Make it take input each time in the loop, not only once like what you are telling the program to do!
Remember, variable names only get their values once, all new values must be done through assignment, so like this:

String yandn = ...; while(yandn.equals("y")) { // more code here yandn = scan.nextLine(); }
Profile icon