Ending experiment depending upon participants' responses

Hi there,

My experiment has certain demographic questions which determine whether the participants qualify for the study or not.

One of my questions has two answers- yes or no. If the participant answers yes, then the experiment continues. If they answer no, then the experiment needs to end with a thank you message.

Secondly, if they mention that their age is below 18, the experiment must also end.

Will coding be required? If so, how will I go about doing this?

Any help would be much appreciated.

Many thanks,

One easy solution is to put a loop around the whole experiment (minus the thank you message at the end), and to put a variable in the number of repetion field " nReps" (e.g. $skipExp)

You can then use a code component changing the variable depending on what the participant wrote in the demographic questions (let’s say that the info box with the yes/no answer is called “question 1”)

In the begin experiment tab

if (((expInfo["question 1"] === "yes")) || ((expInfo["question 1"] === "Yes"))){
   skipExp = 1;
} else {
    if (((expInfo["question 1"] === "no")) || ((expInfo["question 1"] === "No"))){
       skipExp = 0;

The code is in Javascript because I assume this is needed for an online experiment, but the logic is still valid for an experiment running offline (you just need to change the syntax to Python)

The same logic can be applied for age (if age < 18 → skipExp = 0)

1 Like

Hi tandy,

Thank you for replying!

Yes my experiment will be run online. The image below demonstrates what my experiment currently looks like. I have four multiple-choice questions and one question (asking for age). As you can see, I already have multiple loops.

Hence, I am confused as to where the new loop will go. I tried putting it around ‘demoMultiple’ and the do_multi_loop but it is saying there is an error in the syntax. I have replaced ‘question 1’ which the name of my own question.

Would you happen to know why this might be happening?

Many thanks,

What I do is have an exclusion routine which halts the experiment to exclude participants.


if expInfo['age'] == 1:
    text_exclusion.text = 'Thank you for your interest in this study.\n\nHowever, I am only studying adults.\n\nPlease press the escape key or close your browser tab to quit.'
elif expInfo['english'] != '4': # The default text_exclusion.text is about excluding native English speakers.
    continueRoutine = False


if exclusion == 0:
    continueRoutine = False
elif expInfo['depression'] == '2':
    continueRoutine = False
1 Like

Hi wakecarter,

Thank you for your solution. I based my code on the code you mentioned and it worked.

Below is what I did:
#by default, skip the exclusion message and do the experiment
doExp = 1
doExclusion = 0

#if an exclusion criteria is met though, show the exclusion message and don’t do the experiment
if(demo_resp[“blind”] == “1”):
doExp = 0
doExclusion = 1
exclusion_msg = “Thank you for your interest in this study.\n\n However, the study currently focuses on…\n\nPlease press the escape key to exit the experiment”
elif(int(demo_resp[“age”]) < 18):
doExp = 0
doExclusion = 1
exclusion_msg = “Thank you for your interest in this study.\n\nHowever, the study currently focuses on those who are 18 and above.\n\nPlease press the escape key to exit the experiment”

Many thanks,