Logo

Programming-Idioms

History of Idiom 135 > diff from v43 to v44

Edit summary for version 44 by programming-idioms.org:
[Pascal] Variable name x

Version 43

2020-09-30, 09:16:48

Version 44

2020-09-30, 09:18:32

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic.
If there are several occurrences of x in items, remove only one of them. If x is absent, keep items unchanged.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic.
If there are several occurrences of x in items, remove only one of them. If x is absent, keep items unchanged.

Variables
items,x
Variables
items,x
Imports
uses classes;
Imports
uses classes;
Code
i := items.IndexOf(c);
if i <> -1 then
  items.delete(i);
Code
i := items.IndexOf(x);
if i <> -1 then
  items.delete(i);
Comments bubble
items is a container such as TFPList, TList, TObjectList,...
Comments bubble
items is a container such as TFPList, TList, TObjectList,...