Repeat loops problem

How can i do this using less lines?

if counter = 1 then set list1 to paragraphs of result
if counter = 2 then set list2 to paragraphs of result
if counter = 3 then set list3 to paragraphs of result
if counter = 4 then set list4 to paragraphs of result
if counter = 5 then set list5 to paragraphs of result

if counter = 99 then set list99 to paragraphs of result

Hi,

for example you can do it with this:

set theList to {list1, list2, list3, list4, ....... list99}
set item counter of theList to paragraphs of result

Hi cirno,

You don’t usually use that many lists. Just use one list of lists. If you want to create an array, a quick way is to repeatedly concatenate. Here’s an example of making a list of 1024 empty lists.


set l to {{}} -- list of lists; 1 item
repeat 10 times -- 2^10 = 1024 items
	set l to l & l
end repeat

Now you can access sub list items 1 thru 99.

It’s a little faster if you use something else besides empty lists (like integers), but not that much. Not that you can keep a template list of 1024 empty lists and when you need to expand just concatenate to an existing list.

gl,