Inform 7 Home Page / Documentation


§16.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

paste.png 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:

paste.png repeat with N running from 1 to the number of rows in the Table of Selected Elements:
    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]."

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 phrase:

number of rows in/from (table name) ... number

This phrase produces the number of rows (including any blank rows) in the given table. Example:

number of rows in the Table of Selected Elements


arrow-up.png Start of Chapter 16: Tables
arrow-left.png Back to §16.1. Laying out tables
arrow-right.png Onward to §16.3. Corresponding entries