Hi all
Here is my snippet
for(int i = 1;;i++){
System.out.println("Please enter the name:");
name = input.nextLine();
System.out.println("Please enter the email:");
email = input.nextLine();
if(!email.matches(EMAIL_PATTERN)){
System.out.println("Please enter a valid email.\nThe details are not saved please start from the beginning.");
i--;
// break;
continue;
}
else
{
printwriter.println("|"+i+")\t|"+name+"\t|"+email+"\t|");
printwriter.println("+-----\t+-----\t+-----\t+");
}
if(i>=1){
System.out.println("Do you wish to continue ?(y/n)");
String quit = input.nextLine();
if(quit.equalsIgnoreCase("n"))break;
else if (quit.equalsIgnoreCase("y")){
continue;
}
else
{
System.out.println("Please enter either 'y' or 'n'");
//how do I pass the control back to the if(i >= 1) ?
}
}
}
So I am using the scanner to read the name and email from the standard input, for the first time it will not ask the user whether to contiue or quit, from the second time it will ask the user whether he/she wants. So he/she is left with two choices to choose (i.e) y/n, the code works for these two cases, what if the user enters something other than y/n ? for example what if he enters dummy? so for that situation I'd written that else part, but now after printing that message it does nothing, I would like to transfer the control to this if(i >= 1).... How would I do that ?
Thanks
Varun Krishna. P