title: Why 2D array for-loop checking cannot access some values?
body: <pre><code>private static String[][] menuList = {{&quot;Soda&quot;,&quot;10&quot;},{&quot;Coke&quot;,&quot;20&quot;},{&quot;Water&quot;,&quot;5&quot;}};
  
  public Drinks(String menu, String size) {
      setMenu(menu);
      setSize(size);
  }
  
  public void setMenu(String menu) {
      this.menu = menu;
      for (int i = 0; i &lt; menuList.length; i++) {
          if (this.menu.equalsIgnoreCase(menuList[i][0])){
              price = Double.valueOf(menuList[i][1]);
          }else{price = 0.0;}
      }
  }
  </code></pre>
  <p>Then I create object for testing<br />
  I can't get price of the first two rows in menuList[][]
  but I can still get the last one</p>
  <pre><code>    Drinks d = new Drinks(&quot;water&quot;,&quot;L&quot;);
      Drinks e = new Drinks(&quot;coke&quot;,&quot;L&quot;);
      Drinks f = new Drinks(&quot;soda&quot;,&quot;L&quot;);
      System.out.println(d);
      System.out.println(e);
      System.out.println(f);
  </code></pre>
  <p>the output is</p>
  <pre><code>Drink[menu = water , size = L , price = 5.00]
  Drink[menu = coke , size = L , price = 0.00]
  Drink[menu = soda , size = L , price = 0.00]
  </code></pre>
  <p>I just want to know why? And how can I fix this?</p>