Jump to content

Strange script construction using 'for'


Gregory McLeod
 Share

You are about to reply to a thread that has been inactive for 4279 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I wonder if anyone can help me to decipher the following construction using a 'for' flow control.

<q>

Animate(integer piStates, integer piChanges) {

     integer    liIndex;

     integer    liCount;

     integer    liFlag    = 1;

     string     lsAnimation;

     liCount = llGetListLength(gaAnimations);

    for (liIndex = 0; liIndex < liCount; ++liIndex, liFlag = liFlag << 1)

        if ((piChanges & liFlag) != 0) {

            lsAnimation = llList2String(gaAnimations,liIndex);

            if ((piStates & liFlag) != 0) llStartAnimation(lsAnimation);

            else llStopAnimation(lsAnimation);

     }

}

</q>

It is the odd extension to the increment part of the for construction I don't understand.

Can you help?

Link to comment
Share on other sites

You may include several variables in the for loop construct. For instance

 for(i=0, j=100; i<100; i++, j--)

is perfectly legitimate.

In your example:

for (liIndex = 0; liIndex < liCount; ++liIndex, liFlag = liFlag << 1)

 liIndex would be incremented by one and liFlag shifted one bit to the right on each iteration.

In general there is no difference between C and LSLfor loops syntax so you may refer to any C language tutorial available on line.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4279 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...