Sign in to follow this  
Followers 0
loveau

variable's scope of for...next loop

5 posts in this topic

variable's scope of for...next loop

I write some code like:

first:

For $i =1  To 2  Step 1 
 For $i =6  To 7  Step 1 
  MsgBox(0,"in",$i) 
 Next 
 MsgBox(0,"out",$i) 
Next oÝ÷ ÚØ^­ë.جÖ)

the result is:

1 in=6

2 in=7

3 out=1

4 in=6

5 in=7

6 out=2

It' done!

but most program language can write code like the first.

Share this post


Link to post
Share on other sites



Only 3 hours :whistle: .. Dang your doing well compared to my learning curve ;)

Share this post


Link to post
Share on other sites

variable's scope of for...next loop

<snip>

but most program language can write code like the first.

Okay, what's your point? AutoIt obviously can't. Scope is at the function level or the global level. Loops do not have their own scope.

Share this post


Link to post
Share on other sites

For $i =1  To 2  Step 1 
 For $i =6  To 7  Step 1 
  MsgBox(0,"in",$i) 
 Next 
 MsgBox(0,"out",$i) 
Next

This is not good programming practice in any language, regardless of scope issues. Your code makes it impossible to reference the outer loop variable from the inner loop, which is a common need in most nested loop structures.


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

to Valik, PaulIA

Thanks! I see!

AutoIt is a great, and powerful scripting language!

Edited by loveau

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