#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Canada
    Posts
    26
    Rep Power
    0

    Question how to make a condition in a for loop to break and continue?


    Hello;
    I have a question on how to make a condition in loop script.
    this is a simple for loop, that loops something tills it reaches 100, I want to run anther thing after every 5 times that the loops run,
    so in this example, another thing should be run 25 times when the main loops reaches 100.

    I am not sure how to code it.
    if I put the condition if " i==5" it plays only once,

    appreciate your help;

    Code:
    for (var i = 0; i < 100; i++) {
        do something();
       
    }
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,110
    Rep Power
    4103
    You want the Remainder operator to test if a number is evenly divisible by 5.
    Code:
    if (i % 5 === 0){
        doSomething();
    }
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Canada
    Posts
    26
    Rep Power
    0
    it is great, it is working just fine.

    thank you very much for the quick respond;

IMN logo majestic logo threadwatch logo seochat tools logo