# Skipping routine A or routine B in every other repetition of the outer loop

**URL:** <https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298>\
**Category:** Builder\
**Created:** [March 14, 2021, 12:44pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298 "2021-03-14T12:44:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonas\_Tvedt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonas_tvedt/32/14664_2.png) [@Jonas\_Tvedt](https://discourse.psychopy.org/u/Jonas_Tvedt)\
**Post date:** [March 14, 2021, 12:44pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298/1 "2021-03-14T12:44:51Z")

</div>

I have several types of routines that runs in loops within an outer loop like this:

 ![Skärmbild (83)](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/f/0fedb079f04bb4de130e44801f25a9efbffb47d1.png)

I am trying to alternate between skipping one of the two last inner loops (trial2 and trials2b) on each repetition of the first outer loop so that in the first repetition trial2 runs and trials2b is skipped and in the second repetition trial2 is skipped and trials2b runs and so on. Crucially, this order (every other) must continue through all the repetitions of the first outer loop as it is repeated by the second, outermost loop.

Any ideas about how can I achieve this?

Cheers

---

<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:** [March 14, 2021, 1:29pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298/2 "2021-03-14T13:29:14Z")

</div>

If you have a loop counter (or use .thisN) then you could set nReps for one inner loop as loopIdx%2 and the other as 1-loopIdx%2

If you want a random start then add randint(0,2) to loopIdx

---

<div class="post-metadata">

**Author:** ![Jonas\_Tvedt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonas_tvedt/32/14664_2.png) [@Jonas\_Tvedt](https://discourse.psychopy.org/u/Jonas_Tvedt)\
**Post date:** [March 14, 2021, 1:44pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298/3 "2021-03-14T13:44:38Z")

</div>

Thank you for your answer! I’m having some trouble understanding still. Could you specify a little? For example, I wonder where and how I should define loopIdx

---

<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:** [March 14, 2021, 2:09pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298/4 "2021-03-14T14:09:49Z")

</div>

Begin Experiment  
loopIdx = -1

Begin Routine (inside loop)  
loopIdx +=1

---

<div class="post-metadata">

**Author:** ![Jonas\_Tvedt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonas_tvedt/32/14664_2.png) [@Jonas\_Tvedt](https://discourse.psychopy.org/u/Jonas_Tvedt)\
**Post date:** [March 14, 2021, 4:09pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298/5 "2021-03-14T16:09:54Z")

</div>

It does not work quite as I hoped. It skips one of the routines but on the next round of the first outer loop (block\_2to5\_nReps3) it skips the same routine as in the previous round.

Perhaps I made a mistake somewhere? I did like this (nothing more or less):

Begin experiment (in the “trial2” routine):  
loopIdx = -1

Begin Routine (in both the “trial2” and “trials2b” routines):  
loopIdx +=1

Loop around “trial2”:  
loopIdx%2

Loop around “trials2b”:  
1-loopIdx%2

---

<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:** [March 14, 2021, 6:23pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298/6 "2021-03-14T18:23:57Z")

</div>

I’m guessing that each inner loop has an even number of trials.

I notice that you have a routine in the outer loop that isn’t in the inner loops. Try starting loopIdx at 0 and increment it in that loop. Just once per circuit of the outer loop.

---

<div class="post-metadata">

**Author:** ![Jonas\_Tvedt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonas_tvedt/32/14664_2.png) [@Jonas\_Tvedt](https://discourse.psychopy.org/u/Jonas_Tvedt)\
**Post date:** [March 15, 2021, 1:34pm UTC](https://discourse.psychopy.org/t/skipping-routine-a-or-routine-b-in-every-other-repetition-of-the-outer-loop/21298/7 "2021-03-15T13:34:06Z")

</div>

SOLVED: Like you suggested, incrementing in a routine that only repeats once per outer (“middle”) loop circuit was part of the solution. Starting loopIdx at 1 was the other part.

Thank you for your help!
