Java: why isn't the updated value being returned?
<pre><code>  public static int getElementIdx (DOMElement elt) {
        int count = 1;

        for (DOMElement sib = (DOMElement) elt.getPreviousSibling(); 
                 sib != null; 
                 sib = (DOMElement) sib.getPreviousSibling())
        {
            System.out.println("sib " 
              + sib.getTagName () + " elt " + elt.getTagName ());
            if (sib.ELEMENT_NODE == sib.getNodeType () &amp;&amp;
              sib.getTagName () == elt.getTagName ()) {
                    System.out.println (count);
                    count++;
                }
        }
        return count;
    }
</code></pre>

<p>count always returns 1. However, inside the for loop, it returns the incremented count value. This is really strange, I thought declaring a local variable count outside of the for loop should work....</p>
