title: Is it possible to connect the if-code to the else-code in the flow diagram (Java)?
body: <p>I've been working on this problem for 3 hours and I'm stuck</p>
  <p>I have two conditions and I don't necessarily want to split them up using an <code>if-else</code> statement, what I mean by that is given this flow diagram:</p>
  <p><a href="https://i.stack.imgur.com/vLqlg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vLqlg.png" alt="enter image description here" /></a></p>
  <p>I would need the <code>if code</code> to only be executed if its conditions are <code>true</code> and then to pass through the <code>else code</code>, so essentially the outgoing arrow of the <code>if code</code> would end on top of the <code>else code</code>, I know this is not the best in java as my textbook warns against it</p>
  <p><a href="https://i.stack.imgur.com/66WCf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/66WCf.png" alt="enter image description here" /></a></p>
  <p>maybe I can illustrate my problem with some code</p>
  <pre><code>        int digit = -1;
          do
          {
              System.out.print(&quot;Please enter your choise (1-6): &quot;);     
              if (in.hasNextInt()) 
              {
                  digit = in.nextInt();
              }
              else 
              {
                  in.next();
                  System.out.println(&quot; &quot;);
                  System.out.println(&quot;This is a wrong input. Please try again!&quot;);
              }
          }while (digit &gt; 6 || digit &lt; 1);
  // the program is asking the user to read off of a menu with number 1-6 
  // representing different menu items, this ensures that the user inputs 
  // is an integer 1-6 and asks again if not an integer 1-6       
  
          
          String digitName;
          switch (digit)
          {
              case 1: digitName = &quot;Hamburger&quot;; break;
              case 2: digitName = &quot;Pizza&quot;; break;
              case 3: digitName = &quot;Noodle&quot;; break;
              case 4: digitName = &quot;Salad&quot;; break;
              case 5: digitName = &quot;Sandwhich&quot;; break;
              case 6: digitName = &quot;Finish the order!&quot;; break;
              default: digitName = &quot;&quot;; break;
          }
          System.out.println(&quot; &quot;);
          System.out.println(&quot;Your choice is: &quot; + digitName + &quot;.&quot;);
  // the switch statement allows the right menu item to be printed in the above print statements
          
          if (digit == 6) 
          {
              System.out.println(&quot;No need to pay for the delivery fee.&quot;);
              System.out.println(&quot;The total price is $0.0.&quot;);
              System.out.println(&quot;Thank you for using Online Order Program!&quot;);
  // if digit == 6 then then user would like to exit
          }
          else 
          {
  // given the choice of the user from the menu, other than exiting, the program
  // asks the user if they would like meat with their order and this ensures/only 
  // accepts an input from the user &quot;yes&quot; or &quot;no&quot;, if not then prompts the user 
  // again until &quot;yes&quot; or &quot;no&quot; not lower or upper case sensitive  
              System.out.print(&quot;Would you like to have some meat on your &quot; + digitName + &quot;? (Enter yes or no, don't worry about capitals) &quot;); 
              String likeSomeMeatNul = in.next();
              String likeSomeMeat = likeSomeMeatNul.toLowerCase();
                          
              if (!likeSomeMeat.equals(&quot;yes&quot;) &amp;&amp; !likeSomeMeat.equals(&quot;no&quot;)) 
              {
              
                  do 
                  {
                      System.out.println(&quot;\nThis is a wrong input. Please try again!&quot;);
                      System.out.print(&quot;Would you like to have some meat on your &quot; + digitName + &quot;? (Enter yes or no, don't worry about capitals) &quot;);
                      String someMeat = in.next();
                      likeSomeMeat = someMeat.toLowerCase();
              
                  }while (!likeSomeMeat.equals(&quot;yes&quot;) &amp;&amp; !likeSomeMeat.equals(&quot;no&quot;));
              }
          
  // if the user would like meat with their order then the program needs to know 
  // which kind, in this case &quot;beef&quot; or &quot;pork&quot; and the program only accepts inputs
  // &quot;beef&quot; and &quot;pork&quot; not lower or upper case sensitive      
              if (likeSomeMeat.equals(&quot;yes&quot;)) 
              {
                  System.out.print(&quot;Beef or Pork? (Enter Beef or Pork, don't worry about capitals) &quot;);    
                  String beefOrPorkNul = in.next();
                  String beefOrPork = beefOrPorkNul.toLowerCase();
              
                  if (!beefOrPork.equals(&quot;beef&quot;) &amp;&amp; !beefOrPork.equals(&quot;pork&quot;)) 
                  {
                      do 
                      {
                          System.out.println(&quot;\nThis is a wrong input. Please try again!&quot;);
                          System.out.print(&quot;Beef or Pork? (Enter Beef or Pork, don't worry about capitals) &quot;);
                          String enterBeefOrPork = in.next();
                          beefOrPork = enterBeefOrPork.toLowerCase();
              
                      }while (!beefOrPork.equals(&quot;pork&quot;) &amp;&amp; !beefOrPork.equals(&quot;beef&quot;));
          }
  
  // but if the user does not want any meat with their order
  // say they ordered #3 Noodles, they just want noodles without meat
  // I need to prompt the user if still like to order more food
  // it works if the user wants their order with meat, and the program
  // terminates if the user inputs &quot;no&quot; for &quot;Would you like to have some meat?&quot;       
          
          System.out.print(&quot;Would you like to have more food? (Enter yes or no, don't worry about capitals) &quot;);
          String moreFoodNul = in.next();
          String moreFood = moreFoodNul.toLowerCase();
          
          if (!moreFood.equals(&quot;yes&quot;) &amp;&amp; !moreFood.equals(&quot;no&quot;)) 
          {
              do 
              {
                  System.out.println(&quot;\nThis is a wrong input. Please try again!&quot;);
                  System.out.print(&quot;Would you like to have more food? (Enter yes or no, don't worry about capitals) &quot;);
                  String enter_more_food = in.next();
                  moreFood = enter_more_food.toLowerCase();
              
              }while (!moreFood.equals(&quot;yes&quot;) &amp;&amp; !moreFood.equals(&quot;no&quot;));
          }
  //only accepts &quot;yes&quot; or &quot;no&quot; not case sensitive
  </code></pre>
  <p>I thought it would check to see if the condition inside the <code>if (like_some_meat.equals(&quot;yes&quot;))</code> is true or false, if true then execute and move on to the next line, if false move on to the next line, but this clearly isn't the case... it's looking for what happens if it's false and since I didn't put anything, the program terminates. I goes through if <code>like_some_meat.equals(&quot;yes&quot;)</code> is true however.</p>
  <p>How do I get something to execute only if the condition is true and keep moving forward if false? If possible. I'm not sure my code is salvageable if I would have to split it into two separate branches.</p>