Indexed Variables - PowerPoint PPT Presentation

1 / 3
About This Presentation
Title:

Indexed Variables

Description:

Question: Can you specify beforehand the number of cars that will pass by ? Indexed Variables. To solve this problem we introduce the concept of an index. ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 4
Provided by: miasUwi
Category:

less

Transcript and Presenter's Notes

Title: Indexed Variables


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.
  • car1, car2, car3
  • 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 carindex Get value for car 1
  • WHILE ( carindex ! 0 )
  • index index 1 Now get ready
    for next car
  • PRINT Enter number of occupants
  • READ carindex
  • ENDWHILE
Write a Comment
User Comments (0)
About PowerShow.com