# Breaking trial list every X trials

**URL:** <https://discourse.psychopy.org/t/breaking-trial-list-every-x-trials/43746>\
**Category:** Builder\
**Created:** [February 5, 2025, 10:25am UTC](https://discourse.psychopy.org/t/breaking-trial-list-every-x-trials/43746 "2025-02-05T10:25:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![semantic\_learning](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@semantic\_learning](https://discourse.psychopy.org/u/semantic_learning)\
**Post date:** [February 5, 2025, 10:25am UTC](https://discourse.psychopy.org/t/breaking-trial-list-every-x-trials/43746/1 "2025-02-05T10:25:12Z")

</div>

I already came across a similar problem described by people in this thread: [How to Pause a loop?](https://discourse.psychopy.org/t/how-to-pause-a-loop/4906). But none of the solutions seem to make it work.

**PsychoPy version** : 2024.1.5.  
**What are you trying to achieve?:** I have a trial list of 550 items that are presented in random order. Every 20 items, I want to insert a break.

**What did you try to make it work?:**  
I have a “start” routine, where I have a code component with “trial\_count = 0” in the “begin experiment” tab.  
Then, the loop starts. Within the loop, I have two components, the “trial” component and the “break\_routine” component.  
In the “trial” component, there is a code specifying “trial\_count += 1” in the “each frame” tab.  
In the “break\_routine” component, there is a code specifying: “if trial\_count % 20 != 0:  
continue\_routine = False” in the “Begin routine” tab.

**What specifically went wrong when you tried that?:**  
The “break” message is shown after every trial. I moved the code component to the top of the objects in the “break\_routine” component, copy-pasted the code text back-and-forth between different tabs, but nothing seems to change the break message being shown after every trial.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 5, 2025, 10:37am UTC](https://discourse.psychopy.org/t/breaking-trial-list-every-x-trials/43746/2 "2025-02-05T10:37:25Z")

</div>

Your code is failing because you are using continue\_routine = False instead of continueRoutine = False.

However, I would recommend using Routine Settings instead.

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/33):
>
> Use Routine Settings As of 2024.1.0, each standard routine includes its own settings, accessed by a cog in the top left. Routine Settings includes five tabs: Basic, Flow, Window, Data and Testing. So far I have mostly used the Flow tab to either add a duration to the routine or a “skip if” condition. Routine durations are easier than adding durations to every component in the routine separately and works even when a component hasn’t been started because its start condition…

---

<div class="post-metadata">

**Author:** ![semantic\_learning](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@semantic\_learning](https://discourse.psychopy.org/u/semantic_learning)\
**Post date:** [February 5, 2025, 11:07am UTC](https://discourse.psychopy.org/t/breaking-trial-list-every-x-trials/43746/3 "2025-02-05T11:07:29Z")

</div>

Thanks for your fast response! Good news is: It kind of works now (both when I use the code or when I use the Routine Settings, as you suggest).

Bad news: It doesn’t show the break message every 20th trials, but at some intervals that I can’t figure how it gets to (ranging from 6 to 51) - both when I use the “Routine Settings” and the code component.

 ![code](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/9/d984ca3c515d2f6e2ac0186f22df18f8e0082b64.jpeg)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 5, 2025, 11:22am UTC](https://discourse.psychopy.org/t/breaking-trial-list-every-x-trials/43746/4 "2025-02-05T11:22:53Z")

</div>

> [@semantic\_learning](#):
>
> In the “trial” component, there is a code specifying “trial\_count += 1” in the “each frame” tab.

Why is this in Each Frame? I think you are effectively stopping on a random 5% of trials.

If your trials loop is called trials, try `trials.thisN % 20 != 19`
