Howdy, Stranger!

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

Supported by

Restarting a Loop

edited February 2017 in OpenSesame

I have an OpenSesame loop which cycles through a sequence consisting of a sketchpad, keyboard, and logger. I would like the loop to restart from the first cycle after a user makes an incorrect response. Could you tell me how I reset the loop? Thank you!


  • Hi Christopher,

    It is a little tricky to give you an out-of-the-box solution for that problem without actually trying to implement this. In general, I advice you to have two nested loop-sequence constructs. The outer loop is set to a high repeat number with a certain break_if statement, so that it will just keep on running, unless the user breaks out of it. Inside this loop you put the actual trial_loop which is what you keep on iterating until participants finish or make a mistake. Also in this loop you should define a break_if statement, e.g. if correct_response == False: break, or something along these lines. Importantly, you also need to define a variable in the very end of this loop that indicates whether this loop was finished without a mistake or not. This variable you can then use for the outer loop, to decide whether you will break it and continue with the rest of your experiment, or repeat the inner loop again.

    It surely is a little hard to grasp, but do you think you have an idea of what I tried to bring across?


  • Hi Cristopher,

    I think the attached example should help you get started. I added an inline_script item at the end of the trial_sequence

    and placed the following code in the Run_phase tab:

    # If the participant gave an incorrect response:
    if var.correct == 0:
        # Re-execute the whole block_loop item

    Not sure how you want to log and analyze the output, though. Are you going to analyze only the trials that were all correct in a row?



    Lotje van der Linden -

  • Hi,
    I tried using the
    It runs the sequence again but, it runs the next row in the loop.
    I want to run the same row again.

    Details: subjects read a text, than needs to answer questions. If he wants he can press 5 and go back to the text and back again to the same question.

    any suggestions?

    Nachshon Korem

  • Hi,

    So you don't want to repeat a sequence but only a previous item in that sequence. Is that correct? Can you try to replace u'sequence_name with the item's that you want to run?


  • Hi,
    1st thanks for your replay. Yes I tried that, it still continue to the next iteration.
    I found an awful way to do it, add another loop and break it if subject responds.
    Any better ideas?

  • Hi Korem,

    I refuse to think of better ideas if you have a solution that works just fine and doesn't have any other drawbacks than being "ugly" (beauty is in the eyes of the beholder...)


Sign In or Register to comment.