What's the difference between for and repeat?

This forum is currently in read-only mode.
  • They seem pretty similar to me...

    for 0 to 9 = repeat 10 times (or 9 times, i forget )

    anything i should know about?

    redundant?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Repeat just repeats a number of times, and you can only use a positive whole number.

    For can use positive/negative values. For instance, you can

    for x = -10 to 57

    or

    for x = 4 to 90003

    The loop appears to only run forward though, so the end value has to be higher than the start value. Loopindex returns the current value, so if you start counting on 10 then the first loopindex is 10.

    It might be handy to add a Step to the For loop, as in BASIC, so you could do like so:

    for x = 1 to -10 step -1

    that way it would count backwards. Or you could do

    for x = 5 to 20 step 5

    and it would count in increments of 5.

  • Repeat is just a very simple version of For. You can nest For's and still get the current index of the outside loop - because it has a name, so you can do LoopIndex("parent loop name") - but if you nest Repeat conditions, it's impossible to retrieve the index of the outside loop.

    The main reasons it exists are clarity ('Repeat 100 times' in some cases is clearer than 'For "i" from 1 to 100'), and for learning Construct. I've seen a number of new users struggle with the concept of loops in the past, and 'Repeat' is a very simple condition to explain and understand. Once they grasp that, it is much easier to explain a For loop (and other loops) in terms of a Repeat loop.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)