determine array length only once in for loop