question about while loops
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.
well if you wanted it to go once you could change the
yandn variable to
"" as the first thing in the while loop. Then if you want it to repeat then have it ask and then make
yandn equal to
scan.nextLine() then it will repeat the while loop
P.S. I've literally never done Java, I'm just using what I know from python, C# and looking at you code, so could be wrong, but I think it should work.
@xMisbahx sure. So this is what you
while loop should look like:
You'll notice the only difference is the top and bottom of the
while loop. What's happening is
yandn no longer equals "y" so the while loop will not repeat, but at the end it changes it back so that it repeats after the user says to.