| Chapter 15: Tables |

| 15.2. Looking up entries

The simplest way to access the information inside tables is to ask explicitly for it, specifying the row number, the column name and what table is to be consulted. So, given our example table

> Table 2.1 - Selected Elements

> Element | Symbol | Atomic number | Atomic weight
> "Hydrogen" | "H" | 1 | 1
> "Iron" | "Fe" | 26 | 56
> "Zinc" | "Zn" | 30 | 65
> "Uranium" | "U" | 92 | 238

we can write the following description:

> symbol in row 3 of the Table of Selected Elements

to produce the value "Zn". Or the following will run off some chemical data:

> repeat with N running from 1 to the number of rows in the Table of Selected Elements begin;
> say "The atomic weight of [element in row N of the Table of Selected Elements] is [atomic weight in row N of the Table of Selected Elements].";
> end repeat.

The result of which will be:

> The atomic weight of Hydrogen is 1.
> The atomic weight of Iron is 56.
> The atomic weight of Zinc is 65.
> The atomic weight of Uranium is 238.

Note that the first row in a table is row number 1, and that the last can be found with the special value:

> the number of rows in the (name of table here)

Previous | Contents | Next