Bubble sort, runtime error

Hi, I have been trying to make the bubblesort function work for hours. Unfortunately App Inventor doesn’t like it. Everytime I start it, I get an “undefined runtime error”. But I don’t see any mistake.
When I omit the outer FOR-loop it works perfectly (disregarding the fact, that both loops are necessary to conclude the sorting process). The same, when I leave both FOR-loops and remove the IF in between. No error is indicated. But when I put it all together it stops working.
Any ideas? Your help is highly appreciated.

Screenshot_2020-05-02 MIT App Inventor


Use the canonical bubble sort method from Sajal Dutta


There are also extensions that will do this for you:

For strings in Lists: https://amerkashi.wordpress.com/2017/03/05/shuffling-ordering-lists/
For strings and numbers in lists: https://community.kodular.io/t/free-listaddon-extension/24100?u=taifun

Your sort procedure worked., you probably weren’t displaying the local list properly before exitting the local variable scope and destroying it.
See attached …
bug_farm.aia (6.2 KB) Button3 Button3 result

Thank you for your response. I will check the program again. Maybe there is something I overlooked until.

Thank you for your response. I will take a closer look at your suggestions.