title: JS Retry function several times to see if it returns true
body: <p>I'm looking for a better way to retry if a function returns true or false</p>
  
  <pre><code>   function foo() { // 
          var tabList = window.content.document.getElementById('compTabs') // this might be null if page is not loaded and further code wont work
          if (!tabList) { // stop here if tab list is null
              return false;
          }
      // continue and finish function
          }
  
  
  // this is a loop that will go trough an array and this check needs to happen for each element of the array 
  for (var i; i &lt; loopLenght; i++) {
      // This is the actual code nothing else happens here.
          if ( !foo() ) {
              // try again
              if ( !foo() ) {
                  // try one more time
                  if ( !foo() ) {
                      console.log('Failed')
                  }
              }
          }
     // a lot more code coming here that should only run one per iteration
  }
  </code></pre>
  
  <p>I'm just looking for a nicer, cleaner way to write the code above.</p>