title: Return a value present in loop in java
body: <p>I want to return a value from the loop.
  My code is as follows:</p>
  
  <pre><code>public long findLocationId(String location) throws SystemException
      {
  
          long locId = 1;
  
          List&lt;Location&gt; locationList = LocationLocalServiceUtil.getLocations(-1,-1);
  
              for(Location findLoc : locationList)  {
                  if(location == findLoc.getLocationName())  {
                      locId = findLoc.getLocationId();
  
                      **return locId;**
                  }
              }
  
      }
  </code></pre>
  
  <p>When I try to put the return value in loop I get an error saying to include a return statement.</p>
  
  <p>How should I change my code so that I can return a value from the loop itself?</p>
  
  <p>I want to return the new locId value which I get in the loop and not the value which I set initially as locId = 1;
  I want to return the new value of locId which i get from the loop</p>