Skip to content
Sign upLog in

How to repeat the program without running it

Profile icon
huntercanttell

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
sweetmango88

you could use a for or while loop. for your purpose, you would probably want to use the 'while' loop. here is an example of the code:
while(var i=0) {
var ask= prompt("want to repeat?");
if(ask='yes') {
//you put nothing here lol
}
else {
i++;
//and then it stops repeating because i is no longer 0
};
};