AW: Lines, items, repeat loops, > not always what you think

Thomas Fischer fischer at mail.sub.uni-goettingen.de
Tue Oct 18 06:06:06 EDT 2005


Hi Jim,


> Cautionary note:  I have gone to a different method of controlling repeat
> loops now that I am working with database tables.
> 
> (Please note the handlers I have included below to see this 'anomaly' in
> action.)
> 
> In Xtalk, the number of lines or items depends on the delimiter AND if the
> last line/item has anything in it.   Due to this inconsistency, I am now
> using a function ... delimCount()+1  as follows

The number of lines or items does not count an additional empty object at the end: "A,B" and "A,B," both have two items.
I would think this is rather a feature, because I don't have to take care of removing delimiters at the end after creating lists with
put something & comma after myList

If you create your lists otherwise, it depends on the source. Some software will automatically put a line delimiter at the end of a field or text, others won't - but they will be consistent.

But I suppose for your purposes something like

put the number of lines in temp into lineCount
if the last char of temp  is return then add one to lineCount 

would be more efficient and give the same result as your delimCount.

> put fld colorList into temp  --a list of 12 colors
> repeat with x = 1 to delimCount(temp,return) +1
>    answer  line x of temp ‹ which will now do all 12 lines, even 
> if the last
> one is empty
> end repeat

All the best
Thomas Fischer
(Salzburg)




More information about the use-livecode mailing list