common code patterns
ambassador at fourthworld.com
Thu Aug 10 17:02:18 EDT 2017
Monte Goulding wrote:
> Sorry folks I should have been more specific and said using existing
> syntax. So the original thing posted is what I’m after at the moment:
> local tIndex
> put 1 into tIndex
> repeat for each line tLine in tLines
> — code
> add 1 to tIndex
> end repeat
Except that's wrong. :)
I tend to use 0 as the initial value, and increment at the top of the loop:
put 0 into tIndex
repeat for each line tLine in tLines
add 1 to tIndex
I've found two benefits from this habit:
1. (minor) Clearer distinction between unincremented and incremented
2. (major) I can "next repeat" at any point in the block and know that
the counter is appropriately updated.
Indeed, it was a runaway loop many years ago that set me know this path.
All this raises a bigger question: can we for now provide some sparse
minimums and perhaps consider adding more later if truly needed?
Saves work for you folks, and obviates the need to have what would
likely be really long threads here about different coding styles (or
whether all possible styles should be supported in Prefs - "Damnation
to the dangling 'thens'!" <g>).
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the Use-livecode