# Postman Flows - For Loop - End of array processing

**URL:** <https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517>\
**Category:** Help Hub\
**Tags:** loops, postman-flows\
**Created:** [May 1, 2024, 11:44am UTC](https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517 "2024-05-01T11:44:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisdoar](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@chrisdoar](https://community.postman.com/u/chrisdoar)\
**Post date:** [May 1, 2024, 11:44am UTC](https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517/1 "2024-05-01T11:44:59Z")

</div>

All,

Apologies if this has already been asked but I cant see anything and I haven’t been able to figure it out myself. I thought I was making progress with it but the IF block and checking whether the array was populated was a dead end, or at least I didn’t know what I was doing!

My question is, if I have a list of records (3) being read in and a for loop to process each record, is there a way to specify at the end of the loop, to go do something else? In this example below, for each input record I call the MTS API. After the third and final call I want to call a different API to check the results of the previous 3 ‘MTS’ calls. Obviously, if there were 4 input records it would be after the 4th ‘MTS’ call etc…

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/7/a768dfe2e1c79ab7656c081f90a1178f9a2d3195.png)

Thanks in advance,  
Chris

---

<div class="post-metadata">

**Author:** ![chrisdoar](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@chrisdoar](https://community.postman.com/u/chrisdoar)\
**Post date:** [May 1, 2024, 2:06pm UTC](https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517/2 "2024-05-01T14:06:23Z")

</div>

I’ve managed to get this working, but there has to be a better, cleaner way. I’ve added a record number to the input (1,2,3) then created a variable called recCount which is set to 3. In my for loop there is a check on recordNumber and recCount, when they’re equal, do the something else. Is there a better way?

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/3/f3d3b23dda7ac463372e9c9abe4ef9a8d4b0c795.png)

---

<div class="post-metadata">

**Author:** ![flows-daniel](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/flows-daniel/32/25516_2.png) [@flows-daniel](https://community.postman.com/u/flows-daniel)\
**Post date:** [May 1, 2024, 3:28pm UTC](https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517/3 "2024-05-01T15:28:23Z")

</div>

Hi @chrisdoar

If you want to perform an action _after_ all the records have finished looping, you can just put a collect block at the end which will wait until after the loop competes (the collect block will return a list of all the outputs of each iteration of the loop).

---

<div class="post-metadata">

**Author:** ![chrisdoar](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@chrisdoar](https://community.postman.com/u/chrisdoar)\
**Post date:** [May 2, 2024, 8:52am UTC](https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517/4 "2024-05-02T08:52:17Z")

</div>

Thank you again @flows-daniel for the advice. I’ll give that a go.

Kind regards,  
Chris

---

<div class="post-metadata">

**Author:** ![chrisdoar](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@chrisdoar](https://community.postman.com/u/chrisdoar)\
**Post date:** [May 2, 2024, 10:11am UTC](https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517/5 "2024-05-02T10:11:07Z")

</div>

@flows-daniel, I’ve added a collect block and it done exactly what I wanted. Much neater and more concise than I originally had. Thanks for your guidance again 🙂

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/d/9d541d9e2b10c68d78140d97db00df42fe64179d.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [May 5, 2024, 10:12am UTC](https://community.postman.com/t/postman-flows-for-loop-end-of-array-processing/60517/6 "2024-05-05T10:12:07Z")

</div>

Closed on May 5, 2024, 10:12am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
