Terminate a trial after a certain condition was reached N times


I have a simple experiment, comprising Builder components and a bit of code.

The participant has two tasks that alternate and he has to respond by pressing letters on a keyboard to each task. The first task is to respond to a sound – if the sound is low --> press ‘z’, if high -->‘x’. Then he has to respond to a number on the screen – if the number is greater than 45 --> press ‘m’, smaller -->‘n’. And it goes in a loop until the participant reaches 10 consecutive trials with both response times <1s and then it stops.

I think I figured out the condition for the response time <1s but how can I specify that it should be for 10 consecutive trials?

Here is what I’ve got

from psychopy.hardware import keyboard
from psychopy import core
if key_resp_1.rt<1 and key_resp_2.rt<1:
        continueRoutine = False

Thank you!