Page 1 of 1

Iteration through lists and maps

Posted: Wed Aug 15, 2012 9:35 pm
by uwekel
Hi,

to iterate through lists or maps, we do

Code: Select all

ForEach MyList()
  ;here you must access the item with prefix MyList()
Next
If the list variable has a long name, it would be very convenient to have a syntax like

Code: Select all

ForEach i In MyList()
  ;from here you can access the list item just with the prefix i
Next
I know we have the With statement, but it cannot be nested into another With statement. Of course, we can assign the MyList() afterwards e.g. with

Code: Select all

*i.MyStructure = MyList()
but this requires another line of code.

Best regards
Uwe

Re: Iteration through lists and maps

Posted: Wed Aug 15, 2012 10:15 pm
by STARGĂ…TE
you can re-define the ForEach ^^

Code: Select all

Macro ForEachEx(List, As)
	ForEach List : As = @List
EndMacro

Macro ForEach(List, As)
	ForEachEx(List, As)
EndMacro




NewList MyList.i()

AddElement(MyList()) : MyList() = 123

ForEach(MyList(), *i.Integer)
	Debug *i\i
Next