Why do loops crash?

Hello There!
I know that we already have while loops in AI2 but they are not at all convenient because they keep crashing when the loop becomes long, so is there any alternative I could use?

What do you mean by loop crashes?
You might have ended up in an infinite loop
Please share your blocks

That's what I want to make. I want an infinite loop

The maximum number of iterations i have seen the while loop making is 60,00,000 or 6,000,000.

Please share your code. I am not able to understand what you would like to do with the infinite loop

Sorry, but I went on to trying a few other methods and now instead of using 1 nested loop, I am trying the timer-based loop. If it doesn't work I will inform you.

Sure! Good to know that.......

Just use a clock timer with an if/else statement....

1 Like

Tried that but I made it a bit messed up :grimacing: :grimacing: Can anyone help me make it?

Again, post your blocks. We can't guess what you are trying to do.
If you start an infinite loop, App Inventor will freeze and become unresponsive. That's why the app closes itself.
There's no need to create an infinite loop in App Inventor. Like @TIMAI2 suggested, you need to use a clock for that.

2 Likes

Here

Will it be fine if I make a loop using procedure blocks?

I think it's the bugs :

2 Likes

@Salman_Dev the loop is working but i am unable to control my BPM now

I think this "Loop" topic is related to your "Metronome" topic. So please merge these.

Here you get some suggestions, especially from @ABG. You will find that this is by no means as trivial as it initially seems.
https://groups.google.com/g/mitappinventortest/c/2SoKmgGVYvI/m/vtakqWbsFQAJ

See my last sentence as an appreciation to @ABG :
"Thank you for your amazing work. After this crash course with you I will probably be able to prepare students for the math exam." :wink:

In the end - mainly because of the inaccuracy of the Clock component and the fact that the timer does not work in the background on many devices - I took a completely different path.

Note:
Of course there are some approaches to bypass the inaccuracy of the clock (e.g. that of Scott Feguson), but even that does not solve all problems.

In order for the timer to work also in the background (idle / sleep mode, screen off, Doze), you need a Foreground service (which has been possible in AI2 since the nb184 release).
Even REQUEST_IGNORE_BATTERY_OPTIMIZATIONS doesn't help.

The same applies to the Clock.
Otherwise you have to keep the screen alive (→ KeepScreenOn, TaifunTools ext.) or connect the device to the charging cable.

OK, thank you but the app works well in the background. The actual problem is that because I am using the clock component I am unable control the interval between the ticks. Also that the timer interval's minimum value is limited to 4 digits I cannot go less than that neither can I use decimal values.

1 Like

In simple words, I cannot type like this "0008333" or "8.333"

As I already said, definitively not on all devices (e.g. Samsung Galaxy Note8, S8 → Android 9, ...).

OK, it worked in Android 7. That's what I use.

If the app is only intended for your own use, then everything is fine.