In my program I get input from the user (type of topping for a pizza) then if there aren't enough left I have to let them change or cancel that topping.
I do this with a for loop, my question is: how do I make it so it breaks out of the for loop and goes back up to where I get input from the user. Here is a code snippet:
//brings up toppings input dialog
String smallToppings =
JOptionPane.showInputDialog("What kind of toppings do you want on your small pizza?\n\n" +
"We currently have: pepperoni, mushrooms, meatball, sausage, chicken, and ham.\n\n" +
"Please enter your toppings with spaces inbetween (ie. pepperoni ham).\n"
+ "To check the inventory, type in 'checkINV' without the quotes.", "pepperoni mushroom");
//splits each toppings into an array
String[] arr = smallToppings.split(" ");
//counts how many toppings there are (just by words)
for(int k = 0; k <arr.length;k++)
{//start for
smallCount = 0;
if(arr[k].equals(""))
{//start if
smallCount = 0;
}//end if
else
{//start else
smallCount++;
//}//end else
//sets arr[j] to nameToFind (String to search for)
String nameToFind = arr[k];
//sets number of toppings ordered to an array
numToppingsOrderedArray[k] = (smallCount * smallPizza);
//if found, check to see if there are enough, otherwise we can't make it
for(int i = 0; i <toppingsArray.length;i++)
{//start for
if (nameToFind.equals(toppingsArray[i]))
{//start if
//doesn't do anything, just text
JOptionPane.showMessageDialog(null,
"Checking to see if there are enough " + toppingsArray[i] + " left...",
"Checking...",
JOptionPane.INFORMATION_MESSAGE);
//checks to see if there are enough toppings available
if (numToppingsArray[i] >= numToppingsOrderedArray[k])
{//start if
JOptionPane.showMessageDialog(null,
"There are enough " + toppingsArray[i] + " to make your pizza.",
"Success!",
JOptionPane.INFORMATION_MESSAGE);
//removes number of toppings ordered from those on hand
numToppingsArray[i] = numToppingsArray[i] - numToppingsOrderedArray[k];
}//end if
else
{//start else
notAvailable = JOptionPane.showConfirmDialog
(null , "There aren't enough " + toppingsArray[i] + " toppings left." +
"\nWould like you to order something else?"
, "Pizza Palace" , JOptionPane.YES_NO_OPTION);
if(notAvailable == JOptionPane.YES_OPTION)
{//start if
smallCount = 0;
//something goes here...
}//end if
if(notAvailable == JOptionPane.NO_OPTION)
{//start if
smallCount = 0;
}//end if
}//end else
}//end if