How to end a loop by clicking one key (i.e. 'n') or restarting the loop if another key is pressed (i.e. 'y')

OS (e.g. Win10: Asus ):
PsychoPy version (2024.1.5)
Standard Standalone? (y/n) If not then what?:
**What are you trying to achieve?:
In my experiment I want to have a practice trial at the beginning which includes watching different videos and answering a question using a slider.
I would like to include an option at the end of the practice trial which allows the participant to choose if they would like to continue practicing. if yes then they can press ‘y’ and if no then press ‘n’ to exit practice trial and move to trial 1.

What did you try to make it work?:
I have included a keyboard component with the specific key press ‘n’ and ‘y’ iterated. looking at other forum posts I saw a code component which I thought may work, but hasn’t.

What specifically went wrong when you tried that?:
when the practice trial ends i am able to press ‘y’ which allows for the experiment to restart, but when i press ‘n’ this also makes the experiment restart.

I have attached some images of my work, hope this can help solve the issue.



Your trials loop needs to have nReps = a large number

yes @wakecarter I have set my trial reps to 999 to accommodate the unexpected number of repeats a participant may do.

Your keyboard component is called key_resp_2 not key_resp

thank you @wakecarter the keys are now working!!