"While" in a function causing delay before calling it


I’m a noob on Kodular so maybe I am posting something very simpleton, but here I am to ask some help.

I´ve just created a basic app to get familiar with Kodular and I am facing an weird non expected behavior: a time delay using an while loop is happening even before it should be performed, so if you run this app you’ll see that write commands located before this function call are only shown after this loop.

In the attached project you can find it in the “showBTState” function.

BT_teste_copy_4.aia (81.2 KB)

Please show your relevant blocks.

That’s the function I’ve mentioned.

It’s behavioring as if loop was the first thing to do.

Why is a wait procedure generally a bad idea?
The model of event processing in App Inventor by Lyn
Please Wait method by Scott


This an app only for learning purpose. The fact that while loop is executed before other commands catched my attention and, eventually, it may mess with another app. That why I need to understand what makes it happens so.

1 Like

I think these days I had a similar problem, but I didn’t investigate deeply: I wanted to show a simple counter of how many records (from a table) had already been inserted in another table… only showed the end.… the label was blank and only at the end did it show the total of records…
I used to do this at the time of Clipper (there was no graphical environment , only MS-DOS) and it was necessary to show that there was a processing in progress…
So it was a message "Wait…Records : "+ varnumber


I’ve not commented before, but I notice something similar, besides the odd behavior related to the while loop: no label6 text was written during while execution. It’s only presented the content at its end (“count is finished”). Of course, write on label6.text before loop (“starting count”) cannot be seen, but probably there was no enough time to be visually noticeable, I presume.

1 Like

Try this aia and see if it works for you

BT_teste_copy_5.aia (81.7 KB)

@AC_Automacao_e_Controle ,
Well, as I said, it happened but I didn’t bother to solve it. I did it another way (circular progress I think)

Which mean you should be using perfectly with clock component. It is easily achievable


Thanks for your effort.

Have you noticed your app only works at startup? When button3 is clicked, “showBTState” function is called at the end and, surprisingly, it doesn’t perform as expected: label3 and label4 are updated, but not label5. “starting count” appears, but never “count is finish”, as if that point was never reached.

It seems another mistery has been raised! :slight_smile:

Anyway, the original mistery is still on: why that ‘while’ loop was being performed right at the beginning of the ‘showBTState’ function?

Count is finished shows at end


Also code was modified to run once. If you study the blocks you can create a procedure to run the same code many times by simply enabling and disabling clock. Also the problem with loops is that they run the code so fast that you can not see the changes and you get to see just the last one.
The only way to see the progress is by using a clock component that fires at specific time and each time the clock fires you call an item from the loop to show in a label

An example, I have a label and every 1000ms shows a letter, I also have a reset button to stop procedure and a start over

1 Like

I still think it’s weird, but ok…but I’m in a paradox about the statement that the processing is very fast and the message “the app is taking too long to respond: close app or wait” I have 2 processes of 15.000 records in the database. 1 I have no control the other run inside a loop , item by item ( 15.000 records). I don’t understand if it’s fast so why the message.

I’m going to start testing ( after 13h ) with Asynchronous Extension.

I haven’t used the extension mentioned above yet.
After researching I came to @Taifun taifun’s indications on this subject.

And :point_down:
I will change the direction of the tests…

1 Like