Nested Repeat loops

Richard Gaskin ambassador at fourthworld.com
Sat Jun 21 10:22:37 EDT 2014


Peter M. Brigham wrote:
> On Jun 21, 2014, at 2:33 AM, Richmond wrote:
>
>> put 1 into XX
>> repeat until XX>7
>>  do something
>>    put 1 into ZZ
>>        repeat until ZZ>7
>>          do something else
>>             put 1 into YY
>>                repeat until YY>7
>>                    ask "What colour are you socks?"
>>                       if it contains "purple" then
>>                           goto %%%
>>                       end if
>>                       add 1 to YY
>>                 end repeat
>>              add 1 to ZZ
>>          end repeat
>>       add 1 to XX
>> end repeat
>> %%%
>
> I like this. The syntax could be
>    go %n -- eg, %4
>
> then the execution would jump to the statement
>    %n -- eg, %4
>
> (Which would allow really flexible GOTO equivalents that would be independent of script line numbering. I always struggled with the Fortran GOTO statements, since I was always having to renumber my lines when I revised my programs.)
>
> Enhancement request, anyone?

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.

--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  Follow me on Twitter:  http://twitter.com/FourthWorldSys




More information about the Use-livecode mailing list