# Ending a Loop based on time and not number of iterations

**URL:** https://discourse.psychopy.org/t/ending-a-loop-based-on-time-and-not-number-of-iterations/24770
**Category:** Builder
**Tags:** timing
**Created:** [August 31, 2021, 9:34pm UTC](https://discourse.psychopy.org/t/ending-a-loop-based-on-time-and-not-number-of-iterations/24770 "2021-08-31T21:34:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cmag](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cmag/32/30915_2.png) [@cmag](https://discourse.psychopy.org/u/cmag)
#### Post date: [August 31, 2021, 9:34pm UTC](https://discourse.psychopy.org/t/ending-a-loop-based-on-time-and-not-number-of-iterations/24770/1 "2021-08-31T21:34:45Z")

</div>

So, I have designed an experiment where participants are allowed to type as many associated words in a set number of time. The routine and loop work flawlessly for a set number of iterations (lets say 10 responses or something). I can set the number of iterations to 9999 and just have an experimenter time the participant, but I would really like to automate this in PsychoPy.

I have tried reviewing other topics and solutions here on the forums. One solution I’ve tried is adding this snippet of code to each frame tab:

if globalClock \>= 60.0:  
continueRoutine = False  
FreeRecallLoop.finished = True

However, when I add that to each frame, my experiment breaks instantly.

I believe I might not be placing it in the correct part of the code. I’ve been placing it in the “while continueRoutine:” section for this loop.

Any help is greatly appreciated!

---

<div class="post-metadata">

### Author: ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)
#### Post date: [September 1, 2021, 10:22am UTC](https://discourse.psychopy.org/t/ending-a-loop-based-on-time-and-not-number-of-iterations/24770/2 "2021-09-01T10:22:34Z")

</div>

Did you add indentation to that code snippet in the actual code component? If you encase code in triple backticks (```) on Discourse it will retain indentation, but people often don’t realise this and so if you copied it over it may have lost indentation.
