Skip to content
Sign upLog in

How to repeat the program without running it

Profile icon

I was looking around but there isn't very much solid information for JAVA, I am trying to create a scanner question that asks if the user wants to restart the program, like "would you like to restart? Yes/No" kinda thing, does anyone have an idea or code that I can learn from? I want the program to run lines from ex. 3-50. I don't want the code to go ex. 1,2,3,4,5,6 etc. If the user says yes the program will re-run itself and all the scanners in between

You are viewing a single comment. View All
Profile icon

YOu can either do a while loop:
while (i<3){ // run this code in block i++; }alert(i);
or for loop:
for (initial-expression; condition; second-expression){ // run this code in block }alert(i);

or do while:
do { // run this code in block i++; } while (i<3); alert(i);

Hope this helps. PS use an if statement with a button/ prompt(); for that restart thing. I would be really interested if you sent me the project once ur finished!