Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

slight error in doc regarding Continue


  • Please log in to reply
5 replies to this topic
iSkilz
  • Members
  • 14 posts
  • Last active:
  • Joined: 15 Dec 2013

The second example shown on the Continue doc portrays Continue 2 and Continue outer used incorrectly.

 

Here is a simple script which, when run, shows the correct functionality:

outer:
Loop 3
{    Msgbox part 1
    Loop 3
    {    If (A_Index = 2)
            Continue 2
            ; Continue outer
    }
    Msgbox part 2
}


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Perhaps you would like to explain what you think is incorrect about it?

The operative word being "think", since the example is most certainly correct.

Personally, I think your example is less effective:
  • The code below the inner loop never executes, because the inner loop always skips it.
  • The inner loop never executes more than one iteration, so may as well not be a loop.
It boils down to this:
Loop 3
    Msgbox part 1
The purpose of the condition (x*A_Index = 4) is to allow all parts of the code to execute at some point.

iSkilz
  • Members
  • 14 posts
  • Last active:
  • Joined: 15 Dec 2013

In the current example in the doc, the example claims that the code 'continue_outer' would bring you to the label 'continue_outer', when in fact, that does not seem to be the case.

 

As my example shows, continue [2/outer] behaves similarly to continue, not similar to break, as the doc example seems to imply.

 

If i'm mistaken, just chalk it up to newbish mistake.



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
"continue_outer" is not valid code. I assume you mean "goto continue_outer".

goto continue_outer is equivalent to continue outer only because the label is at the end of the loop. That mightn't apply if you changed the code after the label, but then it would be a different example. As implied by the comment, the continue_outer label should point at the end of the block.

ErrorLevel:=ErrorLevel does nothing other than provide a target for the label in older versions of AutoHotkey_L. Would it help to remove this long-obsolete line and add a comment clarifying that the continue_outer label should point at the end of the block?
 

As my example shows,

The original example shows exactly the same thing, but additionally shows how it would be done with goto.
 

not similar to break, as the doc example seems to imply.

I don't know where you got that implication. goto continue_outer skips to the end of the current iteration, and execution then flows into the next iteration (if there is one), like continue.

iSkilz
  • Members
  • 14 posts
  • Last active:
  • Joined: 15 Dec 2013

Run my example using [Continue 2] [Continue outer] and [Goto, continue_outer] (after adding in the label).

 

You'll see the first two methods only run the 'part 1' section, and only the Goto method goes to 'part 2'.

 

Aside from that, I'm done.  By no means did I want you to put my example on the doc. I just thought the doc was misleading in this one point, which is Continue 2.

 

~signing off



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Really? I disagree.
outer:
Loop 3
{    Msgbox part 1
    Loop 3
    {    If (A_Index = 2)
            ; Continue 2
            ; Continue outer
            Goto, continue_outer
    }
    Msgbox part 2
continue_outer:
}
Spoiler