Sign in to follow this  
Followers 0
kylomas

[Solved - RTFM] Unable to modify the loop control TO variable

3 posts in this topic

#1 ·  Posted (edited)

Good Evening,

Consider the following code

local $slen = 5

for $1 = 1 to $slen
    ConsoleWrite('Loop # ' & $1 & ' $slen = ' & $slen & @LF)
    if $1 = 2 then $slen += 2
next

The variable ($slen) gets incremented but the loop only runs 5 times, expected 7 times. Because the increment control variable can be modified I expected to be able to modify the loop exit variable. Can someone verify whether or not loop exit control can be modified?

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yes, you can modified but this value it's read just one time, when the loop starts.

The For loop terminates when the value of variable exceeds the stop threshold. If stepVal or stop is a variable, its value is only read the first time the loop executes.

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Andreik,

Thanks, hitting myself in the head with the RTFM stick...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0