lookup()

Returns a value stored in a table.

Synopsis

lookup(table_name,key-expression)

Description

This function returns the value stored under the given key in the indicated table.

This function is equivalent to table_name[key-expression].

The key-expression may be a single-valued expression or a list-expression. If it is a list-expression, the function returns a list of values, one for each key in the list.

Parameters

table_name

The name of a table variable.

key-expression

An expression that evaluates to a number or to a list.

Returns

If the key does not exist, a run-time error occurs unless the table has a defined default_value property, in which case the default value is returned. In that case, the default value is NOT inserted into the table as the value of the key.

Examples

The following example sets the lookup_value to 3

some_table[40] = 1
some_table[30] = 2
some_table[10] = 3
some_table[20] = 4
erase(some_table,40)
lookup_value = lookup(some_table,5*2)

or

lookup_value = some_table[5*2]

See Also

clear(), erase(), get_keys(), get_values()