For..Until

Share your ideas as to how the documentation can be improved.
sirksel
Posts: 224
Joined: 12 Nov 2013, 23:48

For..Until

Post by sirksel » 03 Jun 2020, 06:55

I just saw a sentence in the documentation I've never noticed before in a decade of using autohotkey, but apparently has been there since v1:

"Until can be used with any Loop or For" (underline added)

I always knew I could do Loop..Until, but I somehow never realized I could do this:

Code: Select all

a := [2,4,6,8,10]
for i in a
  msgbox i
until i>3
I think I missed it because the For-loop page doesn't mention Until (except as a cross-ref), and the Until page doesn't have an example of it being used with a For-loop. Maybe that might be a good additional example for the docs?

As I'm fixing code for the latest v2 alpha, I'm seeing lots of places to simplify code that currently uses an if/break condition inside the for. Super cool -- the wonders of autohotkey! I'm hoping there are no plans to remove this, now that I'm littering it all throughout 10k lines of code... :)

[Mod edit: Moved to 'Suggestions on documentation improvements'.]

User avatar
kczx3
Posts: 1648
Joined: 06 Oct 2015, 21:39

Re: For..Until

Post by kczx3 » 03 Jun 2020, 09:15

Wow... I never saw that either. Neat!

gregster
Posts: 9095
Joined: 30 Sep 2013, 06:48

Re: For..Until

Post by gregster » 03 Jun 2020, 09:19

Perhaps more like this, for v1, the index i itself is not that interesting in this case (apart from being the condition):

Code: Select all

a := [2,4,6,8,10]
for i, val in a
  msgbox % i " : " val
until i>3

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: For..Until

Post by swagfag » 03 Jun 2020, 10:49

literally the first sentence
if ure aching for examples i guess u could replace the enumerator one

Code: Select all

for n in FibF() {
} until MsgBox("#" A_Index " = " n "`nContinue?",, "y/n") = "No"

FibF() {
    a := 0, b := 1
    return (ByRef n) => (
        n := c := b, b += a, a := c,
        true
    )
}
just in case it wasnt ugly enough already

sirksel
Posts: 224
Joined: 12 Nov 2013, 23:48

Re: For..Until

Post by sirksel » 03 Jun 2020, 12:18

Right, I get it. I need to learn to read! :) Anyhow, maybe it's because such a construct doesn't exist with for-loops in several other languages I know... so I read right past those three words?

I guess I wasn't actually proposing my little array snippet as an example for the docs. If you guys go down that road, @gregster's example is much better. Rather, to hit the point home, it might make sense to have the two major variants right up there in the syntax box after the first sentence... one using Loop and one using For, like:

Code: Select all

Loop {
    ...
} Until Expression

For Value1 [, Value2] in Expression {
   ...
} Until Expression
I'm pretty sure I wouldn't have read past it if the syntax box looked like the above. But then again, if you all feel the docs are sufficient, it's OK with me. I'm just a sample size of one, after all. Thanks for your consideration.

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: For..Until

Post by nnnik » 04 Jun 2020, 00:58

No I think that part you mentioned is a chronical illness of the docs. They are not very useable when topics related to one syntax are found on a random page in the docs.

To fix this we would have to switch our entire documentation system though... So don't expect this to happen anytime soon.
Recommends AHK Studio

Post Reply

Return to “Suggestions on Documentation Improvements”