Nested Repeat loops

Alex Tweedly alex at tweedly.org
Sat Jun 21 18:00:54 EDT 2014


On 21/06/2014 15:22, Richard Gaskin wrote:
> At the RevLive conference in Vegas a few yeas back, Robert Cailliau's 
> opening keynote covered some of the most adventurous feature requests 
> I've ever heard anyone suggest for xTalks.
>
> Among them was the notion of named control structures, in part for 
> exactly the reason covered in this thread, the desire to exit a 
> specific loop when loops are nested.
>
> I can't recall the specifics of his proposed syntax, but I remember 
> being impressed by how natural it seemed.  Maybe it was along the 
> lines of:
>
>   repeat with i = 1 to tSomething named "MySomethingLoop"
>       repeat with j = 1 to tSomethingElse named "MyOtherLoop"
>         DoSomethingWith i,j
>         exit "MySomethingLoop"
>       end repeat
>   end repeat
>
> With named control structures we'd never need to worry about line 
> numbers.
>
> I'm not sure if that was submitted as a feature request, but IMO it 
> should be.  And it would be cool to have just about everything else he 
> proposed go into the DB as well - all of it was valuable, very 
> forward-thinking, reflecting the best of many other languages, all 
> presented in a very xTalk way.
I believe it would be even better to (be able to) name both ends of the 
control structure, and thereby get some extra help from the compiler if 
there was any mismatch, as well as a better visual clue when reading the 
code. (Without this, when you see an "exit repeat 'name'" statement you 
need to look backwards to see the named control structure, and then 
forwards to find the matching end; far easier to have the name at the 
end as well).

   repeat for each key K in myArray named "arrayloop"
       repeat with i = 1 to 1000
          if someFunc(K,i) then
              doit K, i
              next repeat "arrayloop"
          end if
      end repeat
      if something() then exit repeat "arrayloop"
   end repeat named "arrayloop

IMO, either or both named clauses should be optional - no need to put in 
both unless you choose to do the extra work for the extra convenience of 
compiler checks, cf. explicitvariables.

-- Alex.




More information about the use-livecode mailing list