Page 1 of 1

Undocumented Feature in Repeat?

Posted: Thu Jul 02, 2015 4:53 pm
by Lagi Pittas
Seems i've got too much time on my hands.

While playing around with the shadowed variable bug I found out that the repeat statement creates its own local variable that does not need to be declared even in Strict Compilation Mode.
The extra bit of info is that variable can then be used later (but not before) outside the repeat loop in the handler.

It is totally scoped Locally so there are no side effects other than to use or not use?

I went through the docs and it doesn't mention this "feature" maybe it's just "known"

Regards Lagi

Re: Undocumented Feature in Repeat?

Posted: Thu Jul 02, 2015 8:47 pm
by phaworth
That's correct Lagi. Don't think there are any downsides to it, I haven't seen it documented anywhere. I seem to recall there's another situation where a variable doesn't need to be explicitly declared but can't remember what it is - maybe matchtext?
Pete

Re: Undocumented Feature in Repeat?

Posted: Thu Jul 02, 2015 10:34 pm
by mwieder
That's true - the loop index doesn't have to be declared explicitly.
I think the idea is that it's supposed to be a temporary variable and so has a limited scope, so there's no need.
For the rare occurrences where I need to check the index after breaking out of the repeat loop, I declare it explicitly in the handler anyway.
I think it makes the code more readable as it conforms to the rest of my code. But you can certainly get by without doing that.