Jump to content
Sign in to follow this  
GEOSoft

For/Next

Recommended Posts

GEOSoft

Not important but could be nice and it's really just for the devs

As it is right now we have to use a variable whaen using the loop.

For $x = 1 To 3
   ; Do whatever.
Next

How difficult would it be to change that so we could also use

For 1 To 3
   ; Do whatever.
Next

What brought it to mind was this

Local $aArray[50]
For $i = 0 To Ubound($aArray) -1
   $aArray[$i] = ""
   For $j = 1 To 3;; $j is never referenced so "For 1 To 3" would have been fine if it worked
      $aArray[$i] &= Chr(Random(97, 122, 1))
   Next
Next

Valik has seen enouugh of the word "curious" so I won't use it.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Valik

Eh, it's not very common to use a loop without needing the variable. I don't see why we need to introduce syntax that's likely to trip up new users just to provide minor syntactic sugar to support a corner case.

Share this post


Link to post
Share on other sites
GEOSoft

Eh, it's not very common to use a loop without needing the variable. I don't see why we need to introduce syntax that's likely to trip up new users just to provide minor syntactic sugar to support a corner case.

I hadn't considered the confusion angle, so question asked and answered. Chalk it up to another brilliant idea gone astray.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
WideBoyDixon

Maybe there's scope in some distant future version for:

Repeat 3
  ; Do some stuff
EndRepeat

WBD

Share this post


Link to post
Share on other sites
Valik

Maybe there's scope in some distant future version for:

Repeat 3
      ; Do some stuff
     EndRepeat

WBD

Not when I can do it 3 different ways already:

Local $i = 1
While $i <= 3
    $i += 1
WEndoÝ÷ Ù«­¢+Ù½ÈÀÌØí¤ôÄQ¼Ì)9áÐoÝ÷ Ù«­¢+Ù1½°ÀÌØí¤ôÄ)¼(ÀÌØí¤¬ôÄ)U¹Ñ¥°ÀÌØí¤ÐìôÌ

Share this post


Link to post
Share on other sites
Richard Robertson

Just think, if we had a goto, you could do it a fourth way.

Local $i = 1
top:
$i += 1
If $i < 3 Then Goto top

Not to be taken seriously.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites
condoman

I would agree to the GOTO only if it could be a computed one.

Share this post


Link to post
Share on other sites
WideBoyDixon

Not when I can do it 3 different ways already:

Is this a bad time to point out that the third one only loops twice? The original post was about not having to use a variable. I know it's not really important but none of these address the original proposal since they all use a variable. As an aside, the documentation says that the variable in a for loop will be created with local scope even if MustDeclareVars is turned on. Does anyone know if the scope is local to the for loop or local to the function?

EDIT: Strike that, I just downloaded the source code from V3.1.0.0 and I see that it's created local to the function.

WBD

Edited by WideBoyDixon

Share this post


Link to post
Share on other sites
GEOSoft

Lets not regress to the GOTO (or GOSUB) discussion again. There are a few people around who probably still have someones boot print embedded on their arse over that.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
weaponx

Loops don't create a new scope.

Nope but the variable created in a For loop will persist after the loop completes, in kind of a strange way.

For $X = 1 to 4
Next
ConsoleWrite($X & @CRLF) ;Output = 5

Share this post


Link to post
Share on other sites
Richard Robertson

Loops create a new scope in languages I use.

Share this post


Link to post
Share on other sites
weaponx

Loops create a new scope in languages I use.

Examples? The For loop is an exception because it doesn't require the dependent variable to exist prior to entry.

Share this post


Link to post
Share on other sites
monoceres

Nope but the variable created in a For loop will persist after the loop completes, in kind of a strange way.

For $X = 1 to 4
Next
ConsoleWrite($X & @CRLF) ;Output = 5
Not very strange. $X in this case is incremented until to doesn't meet the logical test anymore (in this case <=4) and it doesn't fail until $X=5.

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Richard Robertson

C# for sure... I think the Microsoft compiler for C++ does it, but I can't recall.

Share this post


Link to post
Share on other sites
Valik

C++ and C# create a new scope every time you use { }, more or less:

void Test()
{
    // Function scope
    int iFunctionScope = 0;
    {
        // Nested scope
        int iNestedScope = 2;
    }
    // iNestedScope no longer exists
}

AutoIt only has function scope. Variables created inside conditional statements, loops, et cetera still go to function scope and not a new nested scope.

WideBoyDixon, it's called dry-coding and not paying much attention. You get the point at any rate.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.