title: Mooc Fi Loop Confusion
body: <p>I'm trying to solve Mooc.fi Exercise 103, which is to: design a database for a birdwatcher. It contains name and latin name of birds, as well as number of times observed. I'm having issues understanding why the two codes below result in two different answers.</p>
  
  <p>The code commented out is the code that I've made. Everything seemed to work fine until I input the name : XX. When I tried to pass that name into the observation, it prints it's not a bird(twice sometimes)  (although it's added to the arraylist). When I tried to type in an actual name, it ran fine. I'm having issues understanding why the else-clause inside the for-loop causes that? The for-loop above the commented out one runs completely fine but I'm not sure why you would need to add a boolean to ensure it's actually on the arraylist?</p>
  
  <p>public void observed(String name) {</p>
  
  <pre><code>    boolean birdThere = false; 
      for(Bird bird: this.list) {
          if(bird.getName().equals(name) || bird.getLatinName().equals(name)) {
              bird.addObservation();
              birdThere = true;
          }
      }
  
      if(!birdThere) {
          System.out.println("Is not a bird!");
      }
  
      /* //WHY ISN'T THIS WORKING RIGHT???
      for(Bird bird: this.list) {
          if(bird.getName().equals(name) || bird.getLatinName().equals(name)) {
              bird.addObservation();
          } else {
              System.out.println("Is not a bird!");
            }
       }
       */
  }
  </code></pre>
  
  <p>When the commented out for-loop is run with the name: "XX," it prints "it's not a bird!" </p>