title: Backtracking using loops in java?
body: <p>Here's the gist of my code and it's function. It's a pick-where-you-go game to choose your path. For example, if you choose path a at the start, you get to choose between path d and e, and if you chose d you can move to f and g and so on.</p>
  
  <p>I want to add backtracking. For instance, if I choose a in the beginning and go all the way to f, I want to be able to go back to d and have the choice between f and g again, or go all the way back to the starting point and choose b.</p>
  
  <p>My initial thought was to use something to tell the code to go back to a certain line of code when I need to backtrack, but there's no goto in java to my understanding. I have an inkling to use loops. (I'm thinking while loops in particular.) I cannot figure out HOW to structure the loops to backtrack.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class PathGame {
  
  public static void main (String[] args) {
  
  String name = JOptionPane.showInputDialog("Hello! Welcome to my paths! What is your name, adventurer?");
  JOptionPane.showMessageDialog(null, "Well then " + name + ", here's how this works...some generic instructions");
  
  String startingChoice = JOptionPane.showInputDialog("Choose your path, a, b, or c.");
  
  if (startingChoice.equals("a")){
  String aChoice = JOptionPane.showInputDialog("Choose path d or path e");
  
  if (aChoice.equals("d")) {
      String dExamineChoice = JOptionPane.showInputDialog("path f or g?");
     if (dExamineChoice.equals("f")) {
      JOptionPane.showMessageDialog(null, name + "...!");
     }
     else if (dExamineChoice.equals("g")) {
      JOptionPane.showMessageDialog(null, "Stuff g");
     }
  }
  else if (aChoice.equals("e")) {
     JOptionPane.showMessageDialog(null, "Stuff e");
  }
  else if (aChoice.equals("goBack")) {
      ///Backtrack back to start
  }
  }
  else if (startingChoice.equals("b")) {
  String bChoice = JOptionPane.showInputDialog("Path h or i?");
  if (bChoice.equals("h")) {
      String hChoice = JOptionPane.showInputDialog("Path j, k, or l?");
      if (hChoice.equals("j")) {
          String jExamine = JOptionPane.showInputDialog("m or n?");
          if (jExamine.equals("m")) {
              JOptionPane.showMessageDialog(null,"Stuff m");
          }
          else if (jExamine.equals("n")) {
             JOptionPane.showMessageDialog(null,"Stuff n");
          }
      }
      else if (hChoice.equals("k")) {
          JOptionPane.showMessageDialog(null,"Stuff k");
      }
      else if (hChoice.equals("l")) {
          JOptionPane.showMessageDialog(null,"Stuff l");
      }
      }
  else if (bChoice.equals("i")) {
      JOptionPane.showMessageDialog(null,"Stuff i");
  }
      }
  }
  }
  </code></pre>