Howdy, Stranger!

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

Supported by

Breaking the loop after 5 Minutes

Hi all,

I'm sorry if my question may have been asked several times already, but I couldn't find anything appropriate in my research.

My challenge is to finish a loop after exactly 5 minutes, no matter how many rows are left.

For example, I have 5 rows and a subject arrives at row 3 after 5 minutes. I want the loop to end and log rows 4 and 5 as 0. I tried using the break if function but somehow it doesn't work or I'm doing something wrong.

I would be very grateful for a solution.

• Hi @mirko,

the basic idea is to use some code to store the current time stamp before the loop starts, and then set the "break if" property of the loop to an expression that calculates the difference between the current time and the initial stored time stamp.

I set up a working example for you to explore. the task just presents 10 digits in a loop that would repeat 50 times unless 15 seconds go by. I added a variable displaying the time elapsed with every stimulus, just for illustration.

Good luck!

Fabrice.

• Hey @Fab,

thank you very much for this solution. As you may have also seen, I have already asked my question in the post you posted. The solution is good but does not target exactly what I need. So what exactly do I want? I'll try to explain it better.

In your example, the loop will be terminated only after the completion of the respective task. The current task is therefore executed to the end before the loop is interrupted or terminated. However, I would like the loop to end exactly after 5 minutes, regardless of whether the task is still being processed or not.

To explain it better, I try to describe it with my experiment. I present a total of 20 stimuli, i.e. 20 tasks. For each task, the test participants need several seconds or even longer. After solving the task, the subjects have to click on a "Next" button to move to the next task. Now I want the loop to end after 5 minutes, no matter if the subject clicks on the "Next" button or not. With your solution, they have to click first and then the loop ends. But then 5.20 minutes could have passed already.

I hope I have described my problem better. Maybe there is a solution.

• Hi @mirko,

Thanks for your description. I get a better idea of what you're trying to do now.

The solution would depend on your task characteristics... One option would be to set the "Run if" property of all the events in your sequence to only run if the time elapsed is shorter than the interval you're allowing (5 minutes in your description). That's in addition to the "Break if" set up I posted earlier.

In my example, that would consist in adding the following:

Doing this, it should mean that whatever stage of the trial you're at, events won't be initiated if the allowed interval has passed.

Depending on how your task involves, that might be good enough (hopefully).

Now, if you want to interrupt a specific event that can take some time (for example if you participant is typing something in a `form_text_input `object, you can't interrupt it (at least not in a way that only terminates the loop). One idea you could try is to set the duration or timeout property of your events based on a value that you calculate with code before the critical events, but I'm not sure it would work for objects other than the feedback object, because I think that its duration would be set during the "prepare" phase (and so, by definition, it could not be set to the value you'd calculate right before the event is executed). You could try it out and see how far you go.

Best,

Fabrice.

• Hi @Fab,

thank you for your answer. I think the problem is this. A loop always works task by task. As long as the loop "hangs" in a task, the "Cancel" command is not executed. Here is my example experiment with a very short "processing time" (originally it should be 5 minutes and much more itemrows). As you can see the loop ends after clicking the button.

• Hi @mirko,

Maybe the developers or other users will have some useful suggestions but I don't think you can constrain the duration of the form base dynamically. One option would have been to calculate the maximum time left before the form is displayed and set its duration to that value. Unfortunately, the form is prepared before the sequence is executed, so that method cannot work.

I can't see a way around that issue at the moment, sorry... 🤔

Hopefully someone else out there might think of a way around this problem!

Best,

Fabrice.