# Branching routine/conditional loop

**URL:** <https://discourse.psychopy.org/t/branching-routine-conditional-loop/17214>\
**Category:** Coding\
**Created:** [October 13, 2020, 12:48pm UTC](https://discourse.psychopy.org/t/branching-routine-conditional-loop/17214 "2020-10-13T12:48:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lthieffr](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@lthieffr](https://discourse.psychopy.org/u/lthieffr)\
**Post date:** [October 13, 2020, 12:48pm UTC](https://discourse.psychopy.org/t/branching-routine-conditional-loop/17214/1 "2020-10-13T12:48:49Z")

</div>

Dear all,

I’m working on an experiment with @Jbruxelm and @VVV and we encounter some problems with PsychoPy (using version 2020.2.4).

In our experiment, participants will first go through a memorization task which consists of the presentation of 45 words pairs that will be presented 5 times in a randomized order. After memorizing the word pairs, they must complete a ‘recall test’ where they will be presented with the first word of the word pairs and must type in the second word of each word pair. We want participants to have at least a score of 75% (34/45) for the recall test (we do not want the participant to move on to the next phase as soon as he has obtained 75%, he must complete the entire routine). If the participant do not score 75% then he must go through a slightly different memorization phase; this memorization routine will present the 45 word paires only 3 times instead of 5 in the first memorization task. After this second memorization phase, the participant must go through a recall test again, which remains unchanged. We tried to achieve this by creating a ‘dummy loop’ as suggested in this video : [Creating a Trial that Branches -- PsychoPy Mini Tutorials - YouTube](https://www.youtube.com/watch?v=kwbHGnJPEHM&t=316s) but we are confronted with a problem. When the participant don’t score 75% the experiment plays the dummy loop but only presenting the first word pair instead of the 45 word pairs that must be presented 3 times. Can anyone help with this? Here’s the code we used in the ‘loopRapp1’ which is the recall routine (trials is the branching loop).

Begin Experiment  
number\_correct = 0  
print(number\_correct)

Begin Routine  
textFill = “”  
if loopRapp1.thisN == 0:  
number\_correct = 0  
print(loopRapp1.thisN)

End Routine  
#update the number correct  
if RecallTextBox.text == target\_response:  
number\_correct = number\_correct + 1  
if number\_correct \< 34:  
doMemoSiFail = 1  
if number\_correct \> 34:  
doMemoSiFail = 0  
thisExp.addData (“number\_correct”, number\_correct)

 ![Capture d’écran 2020-10-13 à 14.50.34](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/8/281476191dd0974390da26e52c54b1da1672ae14.png)

Sorry if I made some english mistakes,

Lola.
