Code:

var interval = setInterval(function () { //Some code1 if(w > 100) { clearInterval(interval); } }, 10) //Some code2 var interval3 = setInterval(function () { //Some code3 if(left2 > 1 && o2 != 1) { clearInterval(interval3); } }, 10) 

In this case, the actions are performed in the following order:

  1. code1
  2. code2
  3. code3
  4. code1
  5. code2
  6. code3
  7. code1
  8. code2
  9. code3

etc.

And I need:

  1. code1
  2. code1
  3. code1
  4. code2
  5. code2
  6. code2
  7. code3
  8. code3
  9. code3

How to achieve this?

  • one
    where is @AlexWindHope, when you need it, to advise you to first read some book on js, and then take on similar tasks - Specter
  • @Spectre and not destiny to say that this code will be executed asynchronously? - lampa
  • one
    and not destiny to admit the fact that the CU does not wish to turn to the subject literature on its own, but continues to seek help here, does not come to any good encouragement of such an attitude - Specter
  • @Spectre then why send a person to read a book again if he wants to learn so much? You, apparently, on a high this occupation. - lampa

2 answers 2

Run all in one timer, or check which function worked and allow / prohibit another to run.

     for (i=0;i>3;i++){code1} for (i=0;i>3;i++){code2} for (i=0;i>3;i++){code3}