Nested for-loop with delay on each iteration in JavaScript
<p>I am trying to implement a nested for-loop with a delay in each iteration. </p>

<p>So far I've came up with something like this </p>

<pre><code>var maxLoops = 10 ;
var counter = 0;
var counter2 = counter;

var maxLoops = 10 ;
var counter = 0;
var counter2 = counter;

(function nNext() {

  if (counter == maxLoops) return
  counter2 = counter - 1;

  setTimeout(() =&gt; (function next() {

     if (counter2 &gt;= maxLoops) return;

     setTimeout(() =&gt; {
          console.log( "Nester counter :" + counter2);
          counter2++
          next()
     }, 100)

  })(), 1)
  counter++;
  nNext();

})();
</code></pre>

<p>Yet it doesn't work properly. I am trying to make a visual representation of a bubble sort and I need this delay so as to see each step which is kind of impossible if array sorts immediately without this delay. Is it actually possible to implement such thing? Or maybe there is a better way to do this?</p>