When I am halfway through a method I would like to be able to go back to a certain point in it, somewhat like a checkpoint.
When running the code there would be two options: writing either 1 or 2. If 1 is the input I just want it to continue with something else, but if 2 is the input I want it to check if a boolean is true. If that boolean is true, ask again to choose 1 or 2. If the boolean is false, continue with more code.
boolean temp = true;
I would want it to come back to here
Scanner input = new Scanner(System.in);
int choice = input.nextLine;
if(choice==1)
System.out.println("Continue code");
else if(choice==2) {
if(temp) {
Here I want it to come back to the start
}
else {
System.out.println("Continue code");
}
}
I can imagine there might be a function to do this, but I have no idea what it could be. This is for an actual program with more complex stuff, where a while
or do while
loop would not be ideal, but if it is the only way then I would also appreciate being told how that would work.