Counting with a "for each number from .. to ... by ..." condition

I would like to count with a "for each number from .. to ... by ..." condition from 1 to 1000 and display the numbers. With this program, however, only the last number = 1000 is displayed, all other numbers are not displayed. Can anyone tell me why?

counting

Please don't give me any other suggestions on how else to do it (I already know them). I have to do it for a very demanding program in my described way.

Because that is how you have it programmed.

Given the above, I cannot tell you more :wink:

Perhaps you could tell us how you want to store and display your set of numbers, and allow us to provide a solution?

You won't be able to do it with the method you showed, because the loop runs so fast that you won't see the changing values in the label... Instead of a loop, use a Clock with an appropriate interval set, then you will see the changing values.

If I let the program count to 1'000'000 instead of 1'000, it takes about 3 seconds and still only the last number = 1'000'000 is displayed. I simply want to display all the numbers one after the other, i.e. 1, then 2, then 3, etc.... Even if it's really fast, I don't care!

Yes, when a loop is used, the UI is not updated. So you won't see anything happening in the loop on the screen. You can't get around this by using loops. As I wrote above, you can use Clock, or simply use another tool to build an app, such as Android Studio.

That's what I thought. So there really is no way to update the UI when running through a loop? (By the way: What do you mean by UI? The Label?)

Yes, e.g. the label. I don't know why this is, but it's probably Android specific. Notice that when you do something in a long loop, e.g. buttons do not work, and Android reports that the app is not responding.

blocks - 2024-03-02T193050.527

The clock is much slower than loops, but does not crash the UI.

That's exactly where my problem lies. I have very long loops and that's why I didn't want to use a clock (it takes too long - just like you wrote).

So that you know what I'm talking about: I have a list with about 2000 entries. Some of these entries are identical. I now need to find out how many entries are identical. So I take the first entry and compare it with the second entry. If the second entry is identical to the first, I increment a counter by 1. Then I compare the first entry with the third, then with the fourth and so on... until the list is complete.
Then I take the second entry and compare it with the third, fourth, ...
I do this with all 2000 entries in the list.

I would now like to display which of the 2000 entries is currently being checked to see if it occurs more than once in the list.

I hope I have expressed myself clearly...

Can't display double entries at the end of your search? As a list. In Java this could be done using AsyncTask, so just an extension.

I had a similar problem coding a prime number sieve demo app.

You can compromise between a loop for speed and a Clock for visibility if you break the computation into chunks, perhaps 100 items per chunk, one chunk per clock cycle.

P.S. This is a good place to use a dictionary, with the item values as keys and their occurrence counts (initially 0) as values.

That sounds exciting. Do you still have this prime number sieve program? Can we see it?

2016-10-10 11_26_33-5554__build_
2016-10-10 11_28_04-5554__build_
2016-10-10 11_30_17-5554__build_
SieveV2.aia (11.5 KB)


Can you send your project along with this list of 2000 items? I would like to test something.