I've been attempting to create a menu using the 'do' feature in Java. I start by providing the user with a range of options, then I request the user to enter their option through the keyboard and in turn, creating the string variable 'selection'. However when I reference the 'selection' variable in my loop expression, the error indication appears with "selection cannot be resolved to a variable". Why is that so and how can I correct this?
Please refer to the code below.
do{
//output presenting the user with options
System.out.print("A simple Menu\n");
System.out.print("Y - Yolk\n");
System.out.print("N - Naan\n");
System.out.print("X - Exit\n\n");
//request user input using the import.util.*; feature
System.out.print("Enter your selection: ");
String selection=keyboard.nextLine();
// So here the 'selection' string is made
}
//Now here, whatever the user has selected as an option will be
// passed through and more options will appear.
while(selection!="X");
//however I get prompted with the red squiggly line underneath the
//'selection' variable that seems to not recognize 'selection' as a string