I noticed that the standard ForLoop Macro doesn’t behave correctly if you plug a larger integer (i.e. 20) into the “First index” and a smaller integer (i.e. 0) into the “Last Index”.
A simple check at the beginning after assigning a local variable would allow the for loop to know whether to increment or decrement on each loop.
The default behavior of the standard ForLoop is to “always” increment, even if the user plugs a negative value into the “first index”. This proposed ForLoop macro should provide the same behavior if a user plugs a negative value into the “first index” and a bigger value into the “last index”. In other words–it should be safe to implement this right into the standard ForLoop without changing the behavior of any existing projects.
The only way this new macro would change behavior in any existing projects, is if users were using the ForLoop incorrectly (i.e. plugging a larger value into the “first index” and a smaller value into the “last index”, in which case, that would cause the ForLoop to “Complete” immediately without actually looping anything. So, if there are any users using ForLoops in that manner (heaven forbid), they will be affected by this newly proposed behavior. For the sake of improving ForLoop behavior, you can safely consider them casualties not worth worrying about.
#Macro Setup:
#Example of usage:
#Produced result:
(Number at top represents most recent loop)