ForEach MyList() As *MyListElement

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

ForEach MyList() As *MyListElement

Post by Josh »

I think the subject is saying all.
sorry for my bad english
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: ForEach MyList() As *MyListElement

Post by uwekel »

+1!

Or you can use the syntax like in Python:

Code: Select all

ForEach *pointer.MyListStruct In MyList()
In the meantime i use a macro:

Code: Select all

Macro Item(Object, ListOrMap)
  ListOrMap
  Object=ListOrMap
EndMacro

Structure Person
  Name.s
  Age.i
EndStructure

NewList Persons.Person()

AddElement(Persons())
Persons()\Name = "Jim"
Persons()\Age = 30

ForEach Item(*p.Person, Persons())
  Debug *p\Name + " is " + *p\Age + " years old"
Next
I put the Macro into a resident file so it is available all the time.

Best regards,
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: ForEach MyList() As *MyListElement

Post by Joris »

+1 and
As I already had a request and don't wont to create an endless list... I think this one adds up here nice.

ForEach GadgetType()

(case #PB_GadgetType_Button : change color, change text (language), change center etc.)
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply