title: Update global variable from jquery nested function
body: <p>I have a problem with this piece of code:</p>
  
  <pre class="lang-js prettyprint-override"><code>var elements;
  var current = 100;
  
  $(document).ready(function() {
          elements =  = $('.slide').length;
          iterate();
  });
  
  function iterate() {
          $('.slide').eq(current).hide().queue(
                  function() {
                          if (++current &gt;= elements) { current = 0; }
                          $('.slide').eq(current).show();
                          $(this).dequeue();
                  }
          );
  
          // Call this function again after the specified duration
          setTimeout(iterate, 1000);
  }
  </code></pre>
  
  <p>What I'm trying to do is iterate all elements with 'slide' class but I have a problem updating 'current' variable. Its value is always 0. How can I modify a global variable from inside a nested jquery function?</p>