Jump to content

For/Next


Recommended Posts

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!"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!"

Link to comment
Share on other sites

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

Repeat 3
  ; Do some stuff
EndRepeat

WBD

Link to comment
Share on other sites

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¹Ñ¥°ÀÌØí¤ÐìôÌ
Link to comment
Share on other sites

  • Administrators

There's some topic somewhere where I added this:

Loop 10

EndLoop

But there were no perf gains (the only possible benefit as we have so many different loops already) so I got rid of it.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...