Page 1 of 1

wrong list iteration

Posted: Wed Oct 26, 2022 9:54 pm
by William Van Hoecke
Hello,
I upgraded to 2.40 beta 1
The following code is behaving strangly different and incorrect on every browser-page-refresh (F5)
Am I doing something wrong here or could this be a bug ?

Code: Select all

Structure textstructure
  literal.s
  decoration.s
  enterflag.i
EndStructure

NewList list_one.textstructure()
NewList list_two.textstructure()

For i= 0 To 19                                                ;fill list_one with 20 elements
  txt.s + Chr(33+i)  
  AddElement(list_one())
  list_one()\literal = "(" + txt + ")"
Next
AddElement(list_two())                                        ;add 1 element to list_two
SelectElement(list_one(),Random(19,0))                        ;select a random element of list_one
SelectElement(list_two(),0)                                   ;select first element of list_two
AddElement(list_two())                                        ;add 1 element to list_two
SelectElement(list_one(),Random(19,0))                        ;select a random element of list_one
SelectElement(list_two(),1)                                   ;select first element of list_two

Debug "list_one listsize = " + Str(ListSize(list_one()))      ;show that list_one has 20 element 
Debug "list_two listsize = " + Str(ListSize(list_two()))      ;show that list_two has 2 element 
Debug "----------------------"

list_two() = list_one()                                       ;set current element of list_two = current element of list_one

ForEach list_two()                                            ;show all elements of list_two --> should be 2
  Debug List_two()\literal                                    ; but it is different on every F5 
Next list_two() 

Re: wrong list iteration

Posted: Thu Oct 27, 2022 8:28 am
by Peter
use

Code: Select all

CopyList(list_one(), list_two())
instead of

Code: Select all

list_two() = list_one()

Re: wrong list iteration

Posted: Sun Oct 30, 2022 6:20 pm
by William Van Hoecke
Peter ...No can do....

during a loop trough list_one, I only need to copy certain elements form list_one to list_two...
Copylist however copies the entire list (according to documentation).

currently i copy every single value of the structure like this

Code: Select all

List_two()\literal = List_one()\literal
List_two()\decoration = List_one()\decoration
List_two()\enterflag = List_one()\enterflag
but I also have large structure and doing it like above works slow and increases code.