title: If statement return value not being returned in Android
body: <p>Obviously I'm missing something basic here. I have a function where there are return statements all over the function in various if statements. The benefit of that can obviously be debated but I'm running into a situation which I'm not familiar with. </p>
  
  <p>I followed the execution of my program through break points and noticed it proceed as normal to a return statement. However, after reaching that statement it skips the remainder of the function and goes to the return statement at the bottom of the function and returns the value sitting down there. Here are the code snippets, it is hundreds of lines long so I don't want to post the whole thing, just the parts I traced it through:</p>
  
  <pre><code>public Location getBestLocation(Context c){ //the header
  
  else if(gps_enabled &amp;&amp; passive_enabled &amp;&amp; !network_enabled){
          if(hGPSLast != null &amp;&amp; hPassive != null){
              if(hGPSLast.getTime() &gt; hPassive.getTime() &amp;&amp; System.currentTimeMillis() - hGPSLast.getTime() &lt; 300000){
                  return hGPSLast; 
              }else if(hPassive.getTime() &gt; hGPSLast.getTime() &amp;&amp; System.currentTimeMillis() - hPassive.getTime() &lt; 300000){
                  return hPassive; 
              }else{
                  hGPSBest = getGPSloc(c);
                  if(hGPSBest.getTime() == hGPSLast.getTime()){
                      if(hPassive.getTime() &gt; hGPSLast.getTime()){
                          return hPassive; 
                      }else{
                          return hGPSLast; 
                      }
                  }else{
                      return hGPSBest; 
                  }
              }
          }else if(hGPSLast != null &amp;&amp; hPassive == null){
              if(System.currentTimeMillis() - hGPSLast.getTime() &lt;300000){
                  return hGPSLast; 
              }else{
                  hGPSBest = getGPSloc(c);
                  return hGPSBest; 
              }
          }else if(hPassive != null &amp;&amp; hGPSLast == null){
              if(System.currentTimeMillis() - hPassive.getTime() &lt; 300000){
                  return hPassive; 
              }else{
                  hGPSBest = getGPSloc(c);
                  if(hGPSBest != null){
                      return hGPSBest;
                  }else{
                      return hPassive; 
                  }
              }
          }
  </code></pre>
  
  <p>one of the returns in that part of the body is reached, however then the code skips to the very bottom where I have this: </p>
  
  <pre><code>    Criteria criteria = new Criteria();
      String best = lm.getBestProvider(criteria, true);
      //since you are using true as the second parameter, you will only get the best of providers which are enabled.
      def = lm.getLastKnownLocation(best);
      return def;
  </code></pre>
  
  <p>The code is returning "def" which I defined as a blank holder Location object which I was hoping would be filled by the code just above it if for whatever reason none of the returns in the body were reached. What am I missing here? </p>