You'll have to do a test if speed is important. The 10x speed penalty you
mention is because the for loop allocates all the memory it needs and writes
into that memoryspace on the fly. Even if you preallocate the array
yourself, you get a significant speed decrease with "Replace Array Element"
when you have to use a while loop. The alternative is to put a case
structure inside the FOR loop and use a shift register so that you can trip
it into the "false" state where the loop iterates doing nothing for the
remainder of the count. This is generally considered less elegant than a
while loop, but it does save the overhead of Replace Array Element.
If the FOR loop executes *many* times you could try a combination; a WHILE
loop with a preallocated array and a FOR loop to
do, say, 100 chunks. After
each chunk comes out of the FOR loop, use Replace Array Element to copy it
to the allocated memory. I've never tried this though so I don't know what
the speed works out to.
Mike Schaeffer wrote in message
news:tnvt6.76234$lj4.2044070@news6.giganews.com...
>
> I'm using a loop to build an array, and have run into an interesting
> problem. I need the ability to abort the loop in case of a failure,
> but I'm not really willing to pay the penality (10x, due to
> memory allocation, I suppose) of switching from using loop indexing
> on a For loop to loop indexing on a While loop. Ideally, there'd be
> a break feature in the For loop, but I haven't been able to find such a
> feature in the documentation.
>
> Any suggestions? Is preallocation of the array before I pass it into
> a while loop the best I can do?
>
> -Mike
>
>
>