Why is this procedure so slow

I wish I knew how to make my code appear as code. Anyways…
This procedure takes 9 seconds to run. None of my other code is sluggish at all, just this one. The loop is executed 27 times. Is this normal?

starttime = now()
pointer = 11	// point to second week
loop	loopindex counter
	// total points = points this week + prev total points - penalty this week
	TeamStats = arraychange(TeamStats,(array(TeamStats,pointer+1) + 
		array(TeamStats,pointer-6) - array(TeamStats,pointer+2)),pointer+4)
	// total penalties = penalty this week plus prev total penalties
	TeamStats = arraychange(TeamStats,array(TeamStats,pointer+2) + 
		array(TeamStats,pointer-5),pointer+5)

	// total weeks = week played this week + previous total weeks
	TeamStats = arraychange(TeamStats,
		(array(TeamStats,pointer+6) + array(TeamStats,pointer-3)),pointer+7)

	// points per match = total points divided by total weeks (if ≠ 0)
	if array(TeamStats,pointer+7) ≠ 0	// weeksplayed ≠ 0 ?
		TeamStats = arraychange(TeamStats,(array(TeamStats,
		pointer+4) / array(TeamStats,pointer+7)),pointer+8)
	endif
	pointer = pointer + 10	// point to the next week
until counter = (NumberofWeeks - 1)

stoptime = now()	message (stoptime - starttime)

Looks like a lot of heavy lifting here. You are going through the data array and changing items 108 times in total. I don’t know if going to an arrayfilter approach would speed things up that much but it might since it would only go through the data array 27 times. I roughed out a version you can test to see if it improves things, slows things down or makes no difference. Since I don’t have your data array and variables to work with I have not tested this except to check it for a syntax error. Buyer beware!

pointer = 11	// point to second week
loop	loopindex counter
    TeamStats=arrayfilter(TeamStats,{?(seq()=pointer+4,(array(TeamStats,pointer+1) + 
    		array(TeamStats,pointer-6) - array(TeamStats,pointer+2)),
    		?(seq()=pointer+5,array(TeamStats,pointer+2) + 
    		array(TeamStats,pointer-5),
    		?(seq()=pointer+7,(array(TeamStats,pointer+6) +
    		 array(TeamStats,pointer-3)),
    		 ?(seq()=pointer+8 and array(TeamStats,pointer+7) ≠ 0,(array(TeamStats,
    		pointer+4) / array(TeamStats,pointer+7)),import()))))})
    pointer = pointer + 10
until counter = (NumberofWeeks - 1)

thanks Gary. I will check out “arrayfilter” and give this code a try.