title: How to do a "for" loop with asynchronous condition in Javascript?
body: <p>I have this function:</p>
  
  <pre><code>waitForFreeAccnt.prototype.isMemberFree = function () {
      var self = this;
  
      self.api.getMemberInfo(function () {
          var accType = self.api.connect.accountType;
          console.log(accType);
          if (accType === 'FREE') {
              console.log('it is free');
              return true;
          } else {
              console.log('it is not free');
              return false;
          }
      });
  };
  </code></pre>
  
  <p>I would like to wait till the account is free for up to 10 seconds with something like that:</p>
  
  <pre><code>var test = function () {
      for (var start = 1; start &lt; 10; start++) {
          var result = self.isMemberFree();
          console.log(result);
          if (result) {
              break;
          } else {
              self.api.pause(1000);
              console.log('waiting');
          }
      }
  };
  </code></pre>
  
  <p>But it doesn't work because <code>self.api.getMemberInfo</code> is asynch call. This is super frustrating with Javascript. Any other language it would be so simple to do. How do I force the for loop to wait for <code>self.isMemberFree()</code> to finish executing before proceeding with the loop?</p>
  
  <p>Also to note, this is not in browser execution so I don't care about anything hanging.</p>