Searching Arrays

There are many methods for searching arrays for a specific value. Suppose you have several arrays with inventory data. The first array, PartNo(), holds all your inventory item part numbers. The second array, Desc(), holds the description of each of those parts. The third array, Price(), contains the price of each corresponding part. You might keep all the inventory data on the disk and then read that data into the arrays when it is time to work with the data.

An inventory program often needs a lookup routine. A user could type a part number, and the computer program would search the PartNo() array for a match. When it finds one, for example at subscript 246, you could then print the 246th element in the Desc() and Price() arrays, ...

Get Absolute Beginner's Guide to Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.