iterative behaviors (i.e "for ()" in programming)

MoebiusMoebius Member Posts: 194
edited July 2012 in Working with GS (Mac)
Howdy gs developers,
just wondering is there any sort of iterative behavior as the for loop in programming, i mean i know i could use a timer but is there any other way, just wondering.

e.g
var i, a = 0 // initialize a before iteration
for i from 1 to 3 // loop three times
{
a = a + i // increment a by the current value of i
}
print a // the number 6 is printed


PS: I do programming however i haven't reach the point in which i can develop apps.

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited July 2012

    Hi @lightbulb

    Loops aren't really catered for as such in GSC; I wish they were, with a Loop behaviour, that'd be really useful.... maybe one day. There are workarounds though depending on which type of loop you're after.

    In this case, a boolean "toggle" could be used so that the rule(s)/behaviours loop as you want until the condition is met to stop the loop.

    So your example in GSC, would be as follows:

    Make two integer attributes, var and a, both with their values as the default 0.
    Make a boolean attribute called Toggle its value as the default false


    Rule:
    When Toggle is false AND var < 4
    Change attribute Toggle to true
    Change attribute var to var +1
    Change attribute a to a + var
    Change attribute Toggle to false

    Rule:
    When var = 3
    Display Text a

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • ORBZORBZ Member Posts: 1,304
    IMO, timers work best for loops.

    You can set a timer to 0 to make it as fast as possible. Use with caution.
  • HapiappsHapiapps Member Posts: 373
    I agree with ORBZ, but watch the performance and make sure its 100% working because timers can fail every now and then.
Sign In or Register to comment.