Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
How do I modify this code to create a loop inside a loop?

I found this script from a website. The loop ends when it has followed 40 Instagram accounts at a 2-second interval. How do I modify the script so it waits for 10 minutes before repeating the same loop for 3 times? Basically, it goes:

  1. Follow an account and wait for 2 seconds X40
  2. Wait for 10 minutes
  3. Follow an account and wait for 2 seconds X40
  4. Wait for 10 minutes
  5. Follow an account and wait for two seconds X40
  6. Wait for 10 minutes
  7. ---LOOP ENDS---
 var TagFollow = document.getElementsByTagName("button");
 var SearchFollow = "Follow";
 var foundFollow;

 function clickfollow(){
 for (var i = 0; i < TagFollow.length; i++) {
     if (TagFollow[i].textContent == SearchFollow) {
     foundFollow = TagFollow[i];
     foundFollow.click(); 
     break;
      }
 }
 }
var i = 1;
function myLoop() {
   setTimeout(function() {
       console.log(new Date().toLocaleTimeString());
        clickfollow();
        //document.getElementsByTagName("ul")[3].scrollIntoView(false
         i++;
         if (i < 41) {
            myLoop();
          }
     }, 2000)
}
 myLoop();

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You do not need nested loops. You can "linearize" them in single loop (I do not recall the correct therm now). So basically you want loop of 3 * 40 = 120 and after each 40 you need to use increased delay of 10 * 60 * 1000 = 600000. You help yourself by using modulo function i%40. Because you start with 1, the each 40th iteration is when remainder of i divided with 40 is zero.

So basically change if (i < 41) to if (i < 121) and }, 2000) to }, i%40 === 0 ? 600000 : 2000)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!