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

68
Views
How to set for loop javascript custom order number

How to create number like this in javascript loop

  • result '1' also result '1'
  • result '2' also result '2'
  • result '3' also result '3'
  • result '4' back to start result '1'
  • result '5' also result '2'
  • result '6' also result '3'
  • result '7' back to start result '1'
  • result '8' also result '2'
  • result '9' also result '3'
  • I'am sorry' i'am bad english

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

    0

    let result = ""
    
    for(let i = 1 ; i <= 10 ; i++){
    for(let j = 1 ; j <= 3 ; j++){
    
       if(i === 10)
       {
         break;
       }
       
       
      if(i % 4 == 0)
      {
        result += ' result ' + i + ' back to start result ' + j +'\n';
      }else{
        result += ' result ' + i + ' also result ' + j +'\n';
      }
     
      if((i % 3) != 0)
      {
        i++;
      }
      
    }
     if(i === 10)
      {
            break;
      }
    }
    
    console.log(result)

    about 4 years ago · Juan Pablo Isaza Report

    0

    I think you are looking for something like this

    const loop = (from, to, limit) => {
      for (let i = from; i <= to; i++) {
        let number = i % limit === 0 ? limit : i % limit;
    
        //do something with the number
        console.log(number);
      }
    };
    

    Then if you call it like this:

    loop(1, 10, 3);
    

    The logged result is 1, 2, 3, 1, 2, 3, 1, 2, 3, 1

    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!