Executing and exit from a continuous loop with the same button

i would like to start a counter pressing a button.
So I will place a while loop inside a button click that increment my counter on certain conditions.
How can I exit that loop pressing the same button. Being in a loop, it will never trigger the button pressing.
Which is the best practice for something similar?

If I understood the question correctly,you can use this code

And snap your conditions in the while loop

If you are in the “Repeat while” loop, nobody could change the stop/start condition and the button click will not be triggered no more. So you will never exit the loop

I think the solution is not to insert the while loop inside the button click event.
But I can’t figure out how to execute a routine asyncronously.
The event should start it, like a function, but don’t have to wait for it to finish to go on.

Are you describing something like a stopwatch? Where you click and it starts counting and then you click again and it stops?

Yes, it seems so :sweat_smile:

Here’s one way to do this:

Project: Thunkable

1 Like

This should work

Thank you :wink: I was already using Screen Open event But I had some doubts. about using a forever loop inside it. But If a guru like you suggest it, I will follow your suggestion :wink:

In your solution the Start/Stop and Stop variables keep their values inside the repeat until loop, So nobody could change their values and stop the repeat until loop.
If you are inside a repeat until loop or a while loop or whatever loop, no button click will be triggered.

I tried with the Break out of loop block but there was an error in thunkable