Index of same items in a list

Hello, I've been tinkering with MIT App inventor and it was a lot of fun. But of course I've some misunderstanding about some usage of the blocks. Especially when I am doing list involving indexes. As for example, I have a list of number {1,0,1,1} and as suppose its indexes are (in order) {1,2,3,4}. If I were to multiply each number in the list with its index, it should be like this: (1x1)+(0x2)+(1x3)+(1x4) right? But my program did it like this: (1x1)+(0x2)+(1x1)+(1x1). I might have some trouble figuring out this. Does anyone can help me on this.

Yes i think now i understand you :grinning:
Here is how it should be:
this one if you gave it (1 0 1 1 ) and ( 1 2 3 4 ) the output will be 8

And if you want to get how the code make it as string (for debugging):

It will return (11)+(02)+(13)+(14)
Is this what you want?

Yes.But can I know what is in the global list 1 and 2.I'm a bit confussed.

List one will be something like:
blocks (44)
List 2 will be:
blocks (45)

Actually i want the numbers {1,0,1,1} to be multiply by its index not items in a list.

Okay now i understand you, so no need for list2.You can try this one:

As far as i understand from your question you want something like(from your post)


And that's the output here:

1 Like

ummm, see here @MohamedTamer :wink:

Sorting numbers and multiply each numbers

1 Like

But if there are same items,the index will be the same as the 1st.For example, {1,1,0}. First1 =1,second1=1...

Nope,My method won't do that.Becuase i don't use index in list method.I use the number variable directly.Just try it!


As @MohamedTamer said, try this:

Similar to this:


I already try it.However, somehow the result is different.Just like this:

I do get "72" when entered "2351" but when I entered "1011" the answer was wrong.I supposed to get "26",but instead i get "6".I've check why it happened.This is because the 2nd and the 3rd "1" index followed the 1st "1". (1×2^1)+(0×2^2)+(1×2^1)+(1×2^1)=6.I hope you can help me.TQ

Please export your project and post it here.


You lost your place counting from 1 to 4.
It is supposed to be
2 + 0 + 8 + 16 = 26

1 Like

BASE_N_2020.aia (110.6 KB)

Yes, it is supposed to be like that.But, it didn't.

You used the wrong for each block type.
AI2 does not do a good job of offering the for each number block up from the palette.
Here are corrected blocks, draggable

and proof it works.


Or more compact: BASE_N_2020a.aia (110.6 KB)

1 Like

Thank you.I will change the block and try it.

Thanks! I already get the answer .Sorry for causing some troubles.

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