Is there a way to achieve this with delays? How can I coordinate the outer loop to wait for the inner loop to finish, and ensure that each iteration of the inner loop is delayed by 2 seconds? The desired outcome looks like this:
The outer loop will print in the console: 0
The outer loop will pause until the inner loop completes.
The inner loop will print: 0, 1, 2 with a delay of 2 seconds between each iteration.
Then the outer loop will print: 1.
The outer loop will again await the completion of the inner loop.
The inner loop will once more print: 0, 1, 2 with a 2-second delay between each iteration.
And so on.
for (var i = 0; i < 3; i++)
{
alert(i);
for (var j = 0; j < 3; j++)
{
alert(j);
}
}