James A Mohler
James A Mohler

Reputation: 11120

Last key in ordered struct

I am building an ordered struct

stMbr = [:];

Lots and lots of fields get added.

stMbr.Name = "";
stMbr.Address = "";
stMbr.City = "";
...

Eventually I hit the last field that is being added. After the ordered struct is built, I am going to need to process it

for (key in stMbr)  {
   ...
}

When I process the last key, I need to do it note that I hit the last key.

Is there a way to know what the last key is in an ordered struct?

Upvotes: 3

Views: 190

Answers (1)

James A Mohler
James A Mohler

Reputation: 11120

It turns out to not be that hard. I just had to use the keylist() member function

if (key == listlast(stMbr.keylist()))  {
  ...
}

Updated Answer

Rather than reprocessing the same list, just keep the last key

lastKey = listlast(stMbr.keylist());


for (key in stMbr) {
...

if (key == lastKey)  {
  ...
  }
}

Upvotes: 1

Related Questions