PDA

View Full Version : does a list contain an item?


mullins
10-22-2007, 03:57 PM
Another request for trivia I can't seem to locate:

1. Create a list of objects
2. Add an if/else
3. Drag & drop the list onto the conditional...

Alice seems to offer to check whether the list contains a particular object, however it only appears to look at the last object in the list.

Am I misreading this? It is used for something else (number, strings, properties)? Or, is this a bug?

Searching a list to see if it contains an object is a nice classroom example, but students always think they're one up on me when they see this option.

mullins
11-17-2007, 01:48 PM
I assume that the lack of replies means this is indeed a bug, especially since lots of people read the post.

In case you were looking for a solution, I provide a work around as an example of writing a function to search a list for a specific object.
for all in order
if theObject = item from list parameter
return true
else
// do nothing
return false

This is also useful for discussing why I don't want to use for all together (assuming it was available).

Similarly, I use the buggy IEEERemainder and remove last element from a list as examples of extending the language with useful functions/methods.