[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Iterating through a list
From: |
Paul E Johnson |
Subject: |
Re: Iterating through a list |
Date: |
Tue, 25 Jul 2000 18:14:05 -0500 |
Doug Donalson wrote:
>
> Suppose I have a list, call it aList. aList can have members or be empty.
> Suppose that aList is empty and I do the following:
>
> index=[aList create: self];
> while( (aListMember=[index next]) )
> {
> do some stuff
> }
>
1. The while loop will terminate after it finds a nil object in your
list.
2. From swarm 2.1 forward, I believe, you get a seg fault if you send
any message to nil. so if in your"do some stuff" you have [aListMember
doSomething] then this is guaranteed to crash.
3. Instead, do
for (aListMember=[index next];[index getLoc]==Member;aListMember=[index
next])
{
if (aListMember != nil)
do some stuff
}
the getLoc method returns Member for anything in the list, even nils.
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.