common code patterns

Ralph DiMola rdimola at
Fri Aug 11 10:29:29 EDT 2017


Again thanks for chiming in.
Here's an example:

Local tIndex, tDataArray
put getMyRecordSet() into tRS
put 1 into tIndex
repeat while not isEof(tRS)
 Put makeThisRecordIntoAnArray(tRS) into tDataArray[tIndex]
 Add 1 to tIndex
End repeat

Now I can sort the keys of the array to ripple thru the records.

This is what I imagined:

local tDataArray
put getMyRecordSet() into tRS
repeat while not isEof(tRS) with counter tIndex
 Put makeThisRecordIntoAnArray(tRS) into tDataArray[tIndex]
end repeat

Another example:

repeat for each word tWord in tWords with counter tIndex
 switch tIndex
  case 1
   -- first word stuff
  case the number of words in tWords
  -- last word stuff
   -- not first or last word stuff
 end switch
 -- all stuff
end repeat

Ralph DiMola
IT Director
Evergreen Information Services
rdimola at

-----Original Message-----
From: use-livecode [mailto:use-livecode-bounces at] On Behalf
Of Mark Waddingham via use-livecode
Sent: Friday, August 11, 2017 5:25 AM
To: How to use LiveCode
Cc: Mark Waddingham
Subject: RE: common code patterns

On 2017-08-10 19:38, Ralph DiMola via use-livecode wrote:
> To make this even more flexible:
> repeat for each line tLine in tLines with [counter] tIndex [start] 
> [{1}|x] [step] [{1}|y]
> end repeat

Not quite on topic for the thread, but this interested in me in terms of
- what are the use cases?

The common code pattern we see as justification for 'repeat for each line
tLine and index tIndex in tLines' is that it allows you to use the
efficiency of iteration over a primary container, whilst still retaining the
index of the chunk being iterated over. i.e.

   put 0 into tIndex
   repeat for each line tLine in tContainer
     add 1 to tIndex
     if tLine is not line tIndex of tContainer then
       answer "Oh dear - something is *really* wrong"
     end if
   end repeat

So an extension to the syntax with 'index' means you get both pieces of
information and a good amount of duality which justifies its existence.

In what kinds of situation do you find yourself wanting an offset index,
relative to the index of the iterated chunk?

Warmest Regards,


Mark Waddingham ~ mark at ~
LiveCode: Everyone can create apps

use-livecode mailing list
use-livecode at
Please visit this url to subscribe, unsubscribe and manage your subscription

More information about the Use-livecode mailing list