title: for loop in nodejs using q library
body: <p>The following are the functions I have </p>
  
  <pre><code>function start(){
   var deferred = Q.defer();
    for(var i=0; i &lt; 3; i++){
      second()
        .then(third)
        .then(fourth)
        .catch(function(error){
          console.log(error);
        });
    }
    return deferred.promise;
  }
  
  function second(){
  //does an http request
  // returns promise
  }
  
  function third(){
  //does an http request
  // returns promise
  }
  
  function fourth(){
  //takes the response of second and third function
  //and compares the response
  //returns promise
  }
  </code></pre>
  
  <p>Here is the sequence of operations when the file is run:</p>
  
  <pre><code>second function
  second function
  third function
  third function 
  fourth function
  fourth function
  </code></pre>
  
  <p>(I know why this is happening, its due to the I/O request in second and third function)</p>
  
  <p>The sequence of operations I want</p>
  
  <pre><code>second function
  third function
  fourth function
  second function
  third function
  fourth function
  </code></pre>
  
  <p>How do I accomplish this in nodejs?</p>
  
  <p>Here is a follow up to the above question: 
  how to pass values to the functions in the .then(funcCall(value)) so that when the 
  function is actually called it also get a value which it can work on. </p>