How to use for loop?

hello to everyone!!

i am not understand for each in list block
controls_forEach
i want to display the list block’s value one by one in label1 block.
blocks (6)

aia file - test (1).aia (4.4 KB)

The for each loop goes thru all the elements in a list. The first time the loop is executed, the variable "item" will be 54. Executes all the blocks inside the For Each container block, and goes back to the top. Now item will be 32. And so on until there's no more elements in your list.

The problem, I presume is that you want to display those at intervals of time, is that right?
Read this to understand why the elements are not displayed one by one:

For that you will have to use a clock component.

1 Like

but in my case when i was executed the loop, loop show me 34


i am not lying.
aia file - test (1).aia (4.4 KB)

No, if you read the link I posted in my previous reply, you will understand how App Inventor works internally.

2 Likes

Don't ask in multiple communities. Only in the community of the builder you use.

It did show you "54", but the loop is so fast you cant see it, so you only see the last item in the loop. To see them all simply set Lablel1.Text to global list.

1 Like

Thanks :v: :v:

Thanks Sir :v: :v:

I agree, you can ask for help or opinions in any, or as many venues you choose. It should be of no concern to anyone else.

1 Like

You can take it as that but in reality that is technically not right.
You see, any GUI changes during an event handler are not displayed until the event has completed.
So in reality, it never showed 54,32 or 65 on screen. It only showed the last result 34.

It is important to understand this well, because you have to plan ahead when doing this kind of processes.

Here's more to read about it:
https://groups.google.com/forum/#!msg/mitappinventortest/m8i32I2m200/Am3VYo3DTIUJ

1 Like

@Official_Ben10 @m_casky there is a reason for this... the builders get more and more different and an answer in one community might not be the correct answer for the other community
also you are wasting other people’s time… you don’t want that, do you?
therefore next time please first choose the builder you like to use and then ask only in the corresponding community… thank you

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.