Undocumented Feature in Repeat?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 366
Joined: Mon Jun 10, 2013 1:32 pm

Undocumented Feature in Repeat?

Post by Lagi Pittas » Thu Jul 02, 2015 4:53 pm

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

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Undocumented Feature in Repeat?

Post by phaworth » Thu Jul 02, 2015 8:47 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Undocumented Feature in Repeat?

Post by mwieder » Thu Jul 02, 2015 10:34 pm

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.

Post Reply