title: PHP - Exit For Loop After Wrong Answer
body: <p>I'm trying to teach myself PHP. My current exercise combines a form (not included in the code, but it works) that requires the user to enter the name of a city. The loop and the if statement compare the entry with an array of state capitals to return an answer that states whether that city is a state capital or not. </p>
  
  <p>If I leave out the <code>elseif</code> part, the code runs ok, but I have no alternative when the user has entered a city that is not in the array. But with the <code>elseif</code>, the first part of the loop doesn't execute. For example, if I enter "Albany" without the <code>elseif</code>, I get "Albany is the capital of New York." But if I enter it with the <code>elseif</code> statement, it runs the loop until it finds "New York" and it prints "Albany is the capital of New York."</p>
  
  <p>I've googled this, and I've read the books on PHP that I have. And I also know that I'm making a very basic mistake. Any guidance would be greatly appreciated. </p>
  
  <pre><code>for ($i = 0 ; $i &lt; count($stateCapitalNames); $i++)
  
  if ($enteredCity == $stateCapitalNames[$i]) {
  
  print "&lt;p&gt;$enteredCity is the capital of &lt;b&gt;$stateNames[$i]&lt;/b&gt;. &lt;/p&gt;";
  
  
  } elseif ($enteredCity != $stateCapitalNames[$i]){
  
  print "&lt;p&gt;$enteredCity is not the capital of a state.&lt;/p&gt;";
  
  }
  
  ?&gt;
  </code></pre>