Nested ITs

What happens with nested IT's? I had inner and outter "repeat with each" loop with independent IT's in them. No error was given so I thought they may have been given a background 1 and 2. The script didn't work and possibly the nested IT's were a reason.
(ref. SenseTalk Appendix B -- All About 'It')

Many thanks, Bruce roll

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    Bruce:

    The thing you need to be aware of with "it" is that there is only one "it" in any context (frame). So if you have nested repeats that are putting their value into "it", the inner loop is overwriting the value that the outer loop is putting into "it". You'll need to have one of the loops put its iterator value into another variable -- this will tend to be more readable and easier to debug anyway. There are two syntaxes for doing this:
    repeat with myVar=each item of someList...
    
    or
    repeat with each myVar of someList...
    
    Then within the loop you'll just refer to myVar where you're currently referencing "it".

    If you call a handler within a repeat loop, the handler can write to "it" without affecting the "it" in the repeat loop, because the handler has its own context and thus its own "it" variable.

    Hope this helps.
Sign In or Register to comment.