# Problem with sequentiality when using loops

**URL:** <https://discourse.slicer.org/t/problem-with-sequentiality-when-using-loops/27127>\
**Category:** Development\
**Created:** [January 9, 2023, 1:12pm UTC](https://discourse.slicer.org/t/problem-with-sequentiality-when-using-loops/27127 "2023-01-09T13:12:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurabc](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@laurabc](https://discourse.slicer.org/u/laurabc)\
**Post date:** [January 9, 2023, 1:12pm UTC](https://discourse.slicer.org/t/problem-with-sequentiality-when-using-loops/27127/1 "2023-01-09T13:12:20Z")

</div>

Dear community,

I am working in a python script to load 4D images and then repeat the same operations in each time volume. Therefore, my script includes first the loading instructions and then a for loop. I am having trouble with the loop, as it is being executed before the images are completely loaded. If I remove the loop and perform the operations for one only volume, the loop is executed after loading the images, as desired.  
How can I solve this? I mean, how can I guarantee that the for loop is executed once the images are completely loaded?

(I am using Slicer 5.2.1 in linux.)

Regards,  
Laura

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 9, 2023, 3:38pm UTC](https://discourse.slicer.org/t/problem-with-sequentiality-when-using-loops/27127/2 "2023-01-09T15:38:00Z")

</div>

It would help if you could provide a short script that demonstrates the calls you are using. Even better would be an example that replicates the issue using public data (e.g. from the SampleData module).

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 10, 2023, 6:36pm UTC](https://discourse.slicer.org/t/problem-with-sequentiality-when-using-loops/27127/4 "2023-01-10T18:36:56Z")

</div>

Thanks for posting the code. It looks like the issue here is just that you need `range(n_time_volumes)` with the parentheses : )

---

<div class="post-metadata">

**Author:** ![laurabc](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@laurabc](https://discourse.slicer.org/u/laurabc)\
**Post date:** [January 11, 2023, 8:25am UTC](https://discourse.slicer.org/t/problem-with-sequentiality-when-using-loops/27127/5 "2023-01-11T08:25:29Z")

</div>

Thank you, I don’t know how I missed that, I’m so embarrased 😅
