how can i loop a whole code and make it repeat until the user wants to stop.

boolean stop = false;

while (!stop) {

//code to be repeated 


//ask user if he/she wants to stop
if yes stop = true;
}

how would i ask them to stop or not
thank you for the help

This forum is full of examples on how to read input from the keyboard.
Do a little search.

Also check the classes:

Scanner
BufferedReader

This forum is full of examples on how to read input from the keyboard.
Do a little search.

Also check the classes:

Scanner
BufferedReader

so would i do something like this:

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter true to repeat game.");
boolean true = keyboard.next();

if this is right would i do this in the while loop or outside of it
thanks for your help

commented: Still no code tags -1

so would i do something like this:

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter true to repeat game.");
boolean true = keyboard.next();

if this is right would i do this in the while loop or outside of it
thanks for your help

I don't believe that this is correct: boolean true = keyboard.next(); because you can't give your variables names like: true which is a keyword for java.

I was thinking something like:

System.out.println("Enter N to stop game.");
String input = keyboard.next();

if (input.equals("N")) {
  stop = true;
}

But since you have marked the thread solved you probably have already figured it out

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.