1 / 3

Indexed Variables

Indexed Variables. Indexed variables ( arrays ) allow us to use many instances of a particular variable. This means we can specify algorithms which use many occurrences of identical variables easily.

elyse
Download Presentation

Indexed Variables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Indexed Variables Indexed variables( arrays ) allow us to use many instances of a particular variable. This means we can specify algorithms which use many occurrences of identical variables easily. Consider an algorithm to record the number of occupants in a car which pass the university gates each day. Question: Can you specify beforehand the number of cars that will pass by ?

  2. Indexed Variables To solve this problem we introduce the concept of an index. The index points to a particular instance of a variable which can have many occurrences and is enclosed in square brackets after the variable name e.g. car[1], car[2], car[3] Whenever we require a new instance of a variable we augment the variable index. With this concept algorithms can store unknown amounts of related data.

  3. Indexed Variables Example {Algorithm to record number of car occupants. 0 to stop} index 1 { Always ensure index is initialised to 1} READ car[index] { Get value for car 1 } WHILE ( car[index] != 0 ) index index + 1 { Now get ready for next car } PRINT “Enter number of occupants” READ car[index] ENDWHILE

More Related