title: setTimeout in loop to check for a change in bounds
body: <p>This is my code:</p>
  
  <pre><code>var b;
  while(!b){
      setTimeout(function(){
          alert('sss')
          b=1;
      }, 500);
  }
  </code></pre>
  
  <p>and it will not alert 'sss'</p>
  
  <p>What can i do?  </p>
  
  <p><strong>Updated:</strong></p>
  
  <p>I want to get bounds on google maps v3:</p>
  
  <pre><code>function get_bounds(){
              var bounds_;
              while(!bounds_){
                  setTimeout(function(){
                      bounds_=map.getBounds();
                      if(bounds_){
                          var leftBottom=[bounds_.getSouthWest().lat(),bounds_.getSouthWest().lng()]
                          var rightTop=[bounds_.getNorthEast().lat(),bounds_.getNorthEast().lng()]
                          return [leftBottom,rightTop];
                          }
                  }, 500);
              }
          }
  </code></pre>
  
  <p><strong>updated2:</strong></p>
  
  <p>hi patrick dw, i don't know why , but your code doesn't work:</p>
  
  <pre><code>var b;
  function waitForB() {
      setTimeout(function(){
          if(!b)
              waitForB();
          else
              alert('sss');
      }, 500);
  }
  waitForB()
  </code></pre>
  
  <p><strong>updated3:</strong></p>
  
  <p>it is ok now :</p>
  
  <pre><code>var b;
  function waitForB() {
      setTimeout(function(){
          if(!b){
              waitForB();
              b='ss';
          }
          else{
              alert('sss')
          }
      }, 500);
  }
  waitForB()
  </code></pre>