Hi I am having some problem understanding the do-while loop in the following program, and I was hoping for some help:
import java.io.File;
import static java.lang.System.out;
import java.util.Scanner;
class DeleteEvidence {
public static void main(String args[]) {
File evidence = new File("c:\\cookedBooks.txt");
Scanner keyboard = new Scanner(System.in);
char reply;
do {
out.print("Delete evidence? (y/n) ");
reply =
keyboard.findWithinHorizon(".",0).charAt(0);
} while (reply != 'y' && reply != 'n');
if (reply == 'y') {
out.println("Okay, here goes...");
evidence.delete();
out.println("The evidence has been deleted.");
} else {
out.println("Sorry, buddy. Just asking.");
}
}
}
Basically I know how the do-while loop works, as in it executes one time and then checks the conditions. In here the condition is while (reply != 'y' && reply != 'n');
and this is throwing me a little: so we want the program to display this out.print("Delete evidence? (y/n) ");
only when the answer is not 'y' and not 'n'? Am I understanding this correctly?
thanks