On 08/11/2017 02:24 AM, Mark Waddingham via use-livecode wrote:

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

Somewhat similar to Ralph's use cases, this paradigm comes up quite often in my code. Probably the most common case is where I want the performance of a 'repeat for each' loop but don't have a proper iterator to use, so I have to use a doppelganger. Examples here from actual working code:

case 1:
setting up an array of constants:

put 0 into tCount
repeat for each item tConst in tConsts
  put tConst into tArray[tCount]
  add 1 to tCount
end repeat

case 2:
iterating through a cr-separated list and needing to modify lines
(note: this is even more extreme if I need to delete lines):

put tBreaks into tNewBreaks
put 1 into tLine
repeat for each line tBreak in tBreaks
  put item 1 of tBreak into tID
  put the long id of control id tID of the topstack into tObjectID
  put tObjectID into item 1 of line tLine of tNewBreaks
  add 1 to tLine
end repeat
return tNewBreaks

case 3:
parsing data and needing an iterator:

command SetVarFieldColors pFieldName
  local x

  put 1 into x
  set the itemdelimiter to tab
  repeat for each line tLine in field pFieldName
    switch item 3 of tLine
      case "C"
set the forecolor of item 2 to 3 of line x of field pFieldName to sDebugColors["declarations"]
        break
      case "P"
set the forecolor of item 2 to 3 of line x of field pFieldName to sDebugColors["parameters"]
        break
      default
        break
    end switch
    add 1 to x
  end repeat
end SetVarFieldColors


--
 Mark Wieder
 ahsoftw...@gmail.com

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to