At this level of generality, the answer necessarily is “maybe”, but so a typical thing would be to do the iteration in a loop but batched on all batch items at once.
In my courses I always give Thomas’s rule of thumb: A for loop is OK as long as the things you operate on have 100s of items, but if you are down to 10s or single numbers, you are in trouble for efficiency.
While there are cases where it is hard or even not doable without custom kernels, many cases lend themselves to a batch strategy.
Best regards
Thomas