ID:269817
Oct 18 2005, 4:28 pm
|
|
Is there a way to check if a list is empty, preferably usable in an if statement?
|
Oct 18 2005, 4:40 pm
|
|
Use the len property.
|
In response to Mobius Evalon
|
|
Mobius Evalon wrote:
Use the len property. if(list.len) dothis() //If the list has a length greater than zero Of course, the "if(!list.len)" part of that is pretty redundant since !list.len must be true if list.len is not =P. |
In response to Wizkidd0123
|
|
I always use else as an error catcher, E.G.:
if(list.len) dothis() |
In response to Mobius Evalon
|
|
Mobius Evalon wrote:
I always use else as an error catcher, E.G.: if(list.len) dothis() While sometimes it's good to catch cases that should never happen, there's a difference between what can't happen and what shouldn't. If list.len is nonzero, then the if() will catch it. Otherwise the list is empty, period. There is absolutely no way both ifs could fail. The extra if() on the else is useless here. Error catching is a good idea and I recommend it where it's reasonable to use it. What you're doing here is not error catching, though; it's just a foolish waste of time. Lummox JR |