Clearing local variables

Kay C Lan lan.kc.macmail at gmail.com
Sat Apr 30 02:13:08 EDT 2016


On Sat, Apr 30, 2016 at 9:19 AM, Dr. Hawkins <dochawk at gmail.com> wrote:

>  Exiting an outer loop from within an inner  takes
> contortions, but figuring out which end is attached to which if or repeat
> is time consuming.
>
> I know you've figured it out but for any noobs reading this and scratching
their heads here is how I do it - I'm sure the experts will show us
something cleaner and simpler.

Firstly, as Alex said, when ever I type in a repeat, if, or switch I use
comments to tag the beginning, middle and end so I spend less time lost in
my scripts - I still get lost ;-(

I then just use 'tExitCheck' a numerical value to test to see which level
to exit out to; 0 = exit out of all repeat loops. In the message box:

put 0 into tCounter
put 5 into tExitCheck  --initially set to run ALL repeats
repeat with a = 1 to 10 --repeat level 1 =10
  repeat with b = 1 to 10 --repeat level 2 = 100
    repeat with c = 1 to 10 --repeat level 3 = 1000
      repeat with d = 1 to 10 --repeat level 4 = 10000
        repeat with e = 1 to 10 --repeat level 5 = 100000
          add 1 to tCounter
          if ((a = 1) AND (b = 2) AND (c = 3) AND (d = 4) AND (e = 5)) then
--answer exit level
            answer "Exit to Level" with "5" or "4" or "3" or "2" or "1" or
"0" titled "Exit Level"
            put it into tExitCheck
          end if --answer exit level

          if tExitCheck < 5 then exit repeat --to level 4
        end repeat  --repeat level 5

        if tExitCheck < 4 then exit repeat --to level 3
      end repeat  --repeat level 4

      if tExitCheck < 3 then exit repeat --to level 2
    end repeat  --repeat level 3

    if tExitCheck < 2 then exit repeat --to level 1
  end repeat  --repeat level 2

  if tExitCheck < 1 then exit repeat --exit all repeat loops
end repeat  --repeat level 1

put "I did " & tCounter & " repeats, " & (100000 - tCounter) & " less than
All." into msg



More information about the use-livecode mailing list