Howdy, Stranger!

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

Supported by

Break if statement not working

edited January 31 in OpenSesame


I want the loop to break if the participant gets more than three correct. I have put this in the break if field and nothing happens. Any ideas? Thanks so much!!

=len(responses.correct) >= 3 and None not in responses.correct[:3] and 0 not in responses.correct[:3]


  • Hi Mollie,

    having complex if statements in the run if of break if field is quite tricky. It is very easy to mess things up and debugging takes a lot of time. I recommend you use an inline_script and following syntax:

    # this code has to be in the run phase of an inline_script after the keyboard item.
    if len(responses.correct) >= 3:
        if None not in responses.correct[:3]:
            if sum(responses.correct[:3]) == 3:
                print 1
                items['block_loop'].var.break_if = u'always'

    Also you need to make sure that before you enter the block loop, you set the break if field back to never. To do so, paste items['block_loop'].var.break_if = u'never' in an inline_script in the sequence before the block_loop`.

    Hope this helps,


  • Hey Eduard!
    Thank you so much for your response. I am still having trouble making it work. It runs but it does not break the loop after three correct answers. I'm not super sure what I am not doing properly. I have attached the experiment and I would greatly appreciate any help. Thank you so much again.


  • Hi Mollie,

    the problem is that you compute the correct response after the current response has been added to the response history. Add this line responses[0].correct = var.correct to line 5 in your correct_response_2_1_1_1 inline_script and it should work.


  • It works!! Thank you so so much!!

Sign In or Register to comment.