Exit a loop on pavlovia

Have a look through this whole thread: Loop.finished=true No longer working

To distinguish exactly what the problem is, some logging might be helpful. Is it that trials.finished=true isn’t doing anything? Or is it that the condition isn’t being met?

I recommend the following for your JS code:

myCount1 = myCount1 + 1;
console.log(myCount1);
if (myCount1 > 5){
    console.log("Setting trials.finished to true");
    trials.finished = true;
}

These messages will appear in your browser’s JavaScript console, which you can find in Chrome by going to View -> Developer. That will tell you if MyCount1 is updating correctly, and if the condition is ever being met. The big thing to watch out for is if you see multiple instances of the message “Setting trials.finished to true”, because that would mean it’s failing to exit the loop correctly.

Looking back at the other thread you also have a lot of nested loops. Keep in mind that trials.finished will always apply to the most proximal loop to the trial this code is in. You may want to look at dummy trials if you are trying to get out of multiple layers of nested loops. See here: Loop.finished not working

1 Like