36 PsychoPy loops
🏢 Lab class
Loops repeat routines within the loop. To learn more about a loop, you need to click on the name of the loop (e.g., trials). This will open the loop’s property window. Details are explained below—for now the key information is:
- Conditions has the file name of the conditions file.
- Num. repeats defines how often the rows in the conditions file should be repeated.
- Loop type determines if the rows in the conditions file are randomised.
🏠 Self-study
Conditions files must be attached to loops. Note that multiple loops can make use of the same conditions file. For example, the flanker experiment uses the conditions file letter_flanker_input.xlsx for both the loop practiceTrials and the loop trials.
36.1 Loop properties
Click on the loop trials in the flanker experiment to display the loop properties. Note that the column headers of the conditions file are shown in square brackets below the conditions/parameters information:

Here is what the fields in this properties window mean from top to bottom:
36.1.1 Name
The name of the loop. trials in our case.
36.1.2 Loop type
“Loop type” determines if PsychoPy keeps the order of non-header rows in the conditions file or randomises them. These are the options of interest to us:
sequential: The conditions file is not randomised. Trials are presented in exactly the same order as in the conditions file.
If we were to use ‘sequential’ for our conditions file, participants would always start with two congruent trials, followed by two incongruent trials, followed by two neutral trials. This is not what we typically want.1
random: The rows in the conditions file are randomised per loop repeat. Imagine you have four rows in your conditions file (the conditions A, B, C, and D) and you ask for two repeats (“Num. repeats”—see below). This is what PsychoPy will do:
- First repeat
- Take the four conditions and randomise them.
- Example result:
C, D, A, B
- Second repeat
- Take the four conditions and randomise them.
- Example result:
A, D, B, C
- Trial order presented to the participant:
C, D, A, B, A, D, B, C(note how the conditions are presented in groups of four).
fullRandom: The rows in the conditions file are multiplied by the number of repeats and are then randomised. Again, imagine you have four rows in your conditions file (the conditions A, B, C, and D) and you ask for two repeats. This is what PsychoPy will do:
- Multiply conditions by number of repeats:
A, B, C, D* 2 =A, B, C, D, A, B, C, D - Randomise all conditions.
- Example result:
C, D, A, A, B, C, D, B - Note how the four conditions are no longer grouped together.
There is only a difference between ‘random’ and ‘fullRandom’ if the number of repeats is more than 1. If ‘random’ or ‘fullRandom’ is the better choice depends on what you would like to achieve. With ‘random’, you know that your conditions will be evenly distributed across the experiment (because they are presented in groups). You can also reduce the number of stimulus repetitions, if that is a potential issue in your experiment (this is because conditions can only repeat if they happen to be at the end of one group of four and at the beginning of the next group of four). On the other hand, your participants might realise that stimuli are presented in groups of four and they might start to predict what is going to happen next. This would be a confound. Therefore, I tend to go for ‘fullRandom’ if the number of conditions is small (say, around ten conditions) and for ‘random’ if it is larger.2
For both ‘random’ and ‘fullRandom’, the randomisation will always randomise complete rows. That is, if a row includes the information HHSHH, n and incon, these parameters will always stay together.
36.1.3 Is trials
Not relevant for us. Simply leave this ticked.
36.1.4 Num. repeats
How often the conditions file should be repeated. In our flanker task, there are 8 repetitions of 6 conditions, so 48 trials overall.
Note: Setting “Num. repeats” to 0 will skip all routines in the loop. This can be useful during task development.
36.1.5 Selected rows and Random seed
Not relevant for us.
36.1.6 Conditions
The name of the conditions file (including the path3). To add a conditions file to a loop, click on the folder icon, navigate to the file and add it to the loop.
36.2 Adding and removing loops
To add a new loop to an experiment, you need to click on “Insert Loop” in the flow panel (or on Experiment → “Insert Loop in Flow” in the menu bar). Then, click on the timeline where you want the loop to begin.
- If there is just one routine in the experiment, this will automatically bring up the property window discussed above. You can then edit the relevant properties and click on OK.
- If there are multiple routines in the experiment, PsychoPy expects you to click on the location where you want the loop to end first. Once you have done so, the properties window will appear.4
To remove a loop, right-click on the loop and then click on “remove”.
36.3 Confirmation
Please confirm you have worked through this chapter by submitting the corresponding chapter completion form on Moodle.
This option is there as sometimes we pre-randomise files, for example to exclude stimulus repetitions. If you pre-randomised a file, you do want PsychoPy to present trials in exactly the order they are in in the conditions file.↩︎
If you have more than two repeats, say four, an alternative would be to combine the two approaches. That is, you could have
A, B, C, D, A, B, C, Din your conditions file and then opt forrandomand two repeats.↩︎PsychoPy will automatically add the correct path for you if you click on the folder icon to add the conditions file, provided you have saved the experiment before adding the conditions file. If conditions file and experiment file are in the same folder, only the file name is required.↩︎
Sometimes it happens that the loop endpoint on the timeline moves when you move the mouse pointer to the properties window. If this happens, you have to delete and reinsert the loop. If you move the mouse pointer straight up from where you clicked, you can avoid this happening.↩︎