Jump to content

Recommended Posts

Posted

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.

Posted

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.
Posted

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
Posted (edited)

to Valik, PaulIA

Thanks! I see!

AutoIt is a great, and powerful scripting language!

Edited by loveau

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
×
×
  • Create New...