Loop-Counter Variable

Does the optional Loop-Counter Variable count up regarless if the loop completes or not?

If I have the Loop number set to 15 but it exits on 5 does the varible return 5 or 15?

The loop counter variable will return whatever value it has when the loop ends. If you use [LoopExit] to exit the loop then it will be the value at that point (at the start of that iteration). The starting value is 0, so if the loop code only executes once the value of the loop counter will still be 0.

If you are using the loop counter variable in code it is good policy to use [Val,loopcounter] rather than just #loopcounter. For example:

      [Note,[StrMerge,"Loop counter value is : ",[Val,n]],,1]
      [LoopExit] // at this point the loop counter variable is >5
[Note,[StrMerge,"Loop counter END value is : ",[Val,n]],,1]

As you’ll see, the loop ends as soon as the loop counter is above 5 - so the end value is 6.

Thanks for the quick reply Marcus.
Interesting. That is the way I assumed it worked. I didn’t know about the [Val] tho.

The reason I ask is I am trying to easily return to a subtool (without having to mess with the blasted scroll bar) by looping “Select Down” after looping “Select Up” to get to the top subtool.


[VarSet,totalSubTools,[StrExtract,[IGetTitle,Preferences:Misc:SubTools Count],10,256]] 
[IPress, Tool:SubTool:SelectUp],

[Loop, [Val,loopCount], [IUpdate]
[IPress, Tool:SubTool:SelectDown]]]

However it seems to be pressing “Select Down” the total number of loops subtools NOT the loopCount Variable. It returns to the bottom of the list not the previously active subtool. I must be doing something wrong. If there is a better way to do this in general I am open for suggestions.

Your problem here is due to your use of [IExists] for testing the SelectUp button. The button always exists, so the loop continues even after the top subtool is reached. What you need instead is [IsEnabled], then all will be well.

Ah perfect! I knew it was some little mistake. Thanks so much Marcus! Where would I be without you?! Saved the day once again.