Depends on how the rest of code is written. Looping on array in general consumes lot of gas. Sometimes, its the only way available, still a bad practice