# Conditional Loops

**URL:** <https://discourse.psychopy.org/t/conditional-loops/13803>\
**Category:** Online experiments\
**Created:** [May 29, 2020, 8:23pm UTC](https://discourse.psychopy.org/t/conditional-loops/13803 "2020-05-29T20:23:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![itreves36](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/itreves36/32/9086_2.png) [@itreves36](https://discourse.psychopy.org/u/itreves36)\
**Post date:** [May 29, 2020, 8:23pm UTC](https://discourse.psychopy.org/t/conditional-loops/13803/1 "2020-05-29T20:23:04Z")

</div>

URL of experiment: [https://run.pavlovia.org/Itreves36/markovsequence/html](https://run.pavlovia.org/Itreves36/markovsequence/html)  
code: [https://gitlab.pavlovia.org/Itreves36/markovsequence](https://gitlab.pavlovia.org/Itreves36/markovsequence)  
Description of the problem:  
Can’t exit loop in online experiment. I want the participants to be able to end a loop of flashed stimuli by pressing the spacebar. I know this is a problem lots of people have been having. I’ve tried a lot of the approaches others have taken. For example:  
stimuli.finished = True/ stimuli.finished = true (actual loop name)  
trials.finished = true (generic loop name)  
ContinueRoutine = false  
skipThisTrial = true

And various combinations. What’s the go-to approach? Thanks!

---

<div class="post-metadata">

**Author:** ![aisa2](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aisa2/32/8666_2.png) [@aisa2](https://discourse.psychopy.org/u/aisa2)\
**Post date:** [May 29, 2020, 9:19pm UTC](https://discourse.psychopy.org/t/conditional-loops/13803/2 "2020-05-29T21:19:52Z")

</div>

I can’t access your code by this link; maybe others can.  
I think we will need more details about the loop before we can help. Is it a for loop? A while loop? How many routines are inside your loop?  
For example, if you are in Builder and you put continueRoutine in a code element, it will only quit out of the routine, and not out of a trial loop that you have put around it.

---

<div class="post-metadata">

**Author:** ![itreves36](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/itreves36/32/9086_2.png) [@itreves36](https://discourse.psychopy.org/u/itreves36)\
**Post date:** [May 30, 2020, 9:02pm UTC](https://discourse.psychopy.org/t/conditional-loops/13803/3 "2020-05-30T21:02:57Z")

</div>

I resolved this. I followed [Loop.finished=true No longer working](https://discourse.psychopy.org/t/loop-finished-true-no-longer-working/11190) ,  
but had to make sure that none of my loops were named ‘trials’ .  
Weird

---

<div class="post-metadata">

**Author:** ![aisa2](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aisa2/32/8666_2.png) [@aisa2](https://discourse.psychopy.org/u/aisa2)\
**Post date:** [May 31, 2020, 2:26pm UTC](https://discourse.psychopy.org/t/conditional-loops/13803/4 "2020-05-31T14:26:25Z")

</div>

I think PsychoPy reserves some variable names for its own internal workings; for example it’s a bad idea to use things like thisTrial or thisLoop.
