Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

How to break a loop after three consequtive wrong responses?

Hi everybody,

I'm preparing an experiment in which participants need to give an answer (wrong or correct). I see the "break-if" button on the loop and it breaks the experiment after one wrong answer with the command "[correct]= 0", but I want to break the loop when participants give three consequitive wrong answers. This means that a new variable should also be use to reset the value when participants give a correct answer inbetween e.g. after two incorrect answers. Any idea?

I understood that I need to create the new variable with an inline_script before this loop. I just wrote there "var.wrong_response =0" and then into the loop I tried #

if var.response == var.correct_response:

var.wrong_response = 0

else:

var.wrong_response += 1

if var.wrong_response >= 3:

exp.end() or break or var.break_loop = True else var.break_loop =False


but nothing works. Could you please help me figure out a working solution?

Many thanks in advance.

Comments

  • Hi @Chichi ,

    you can put in the run_if field of the loop break_loop==True and initialize this variable as False (like you do correctly with wrong_response . Then you do

    if var.wrong_response >= 3:

    break_loop = True

    And that should be it.

    Eduard

    Buy Me A Coffee

  • Hi Eduard,

    thank you for your reply! I inserted 'var.break_loop=False" into the inline_script before the test_loop (in which I put 'break_loop==True' in the 'run_if' field). Thereafter I wrote the following code in a new inline_script of the wanted loop:

    if var.response == 1:

    var.wrong_answers = 0

    else:

    var.wrong_answers += 1

    if var.wrong_answers >= 3:

    break_loop = True

    (shorter codes didn't work). This code breaks the loop after three correct responses. Unfortunately changing 'if var.response == 1:' to 'if var.response == 0:' does not fix the problem and the experiment breaks after three trials, no matter if the answer was correct or not.

    Further ideas? Thank you!

    Chiara

  • Hi,

    I could figure it out!

    I just needed to change the variable 'var.response' to 'var.correct' and now it works perfectly.

    Thanks a lot!

Sign In or Register to comment.