Functions

/Users/garethloy/Musimathics/Musimat1.2/MusimatTutorial/B0114.cpp File Reference

#include "MusimatTutorial.h"

Go to the source code of this file.

Functions

 MusimatTutorialSection (B0114)

Function Documentation

MusimatTutorialSection ( B0114   )

Definition at line 2 of file B0114.cpp.

References x, and y.

                              {
        Print("*** B.1.14 Accessing List Elements ***");
        /*****************************************************************************
         
         B.1.14 Accessing List Elements
         
         We can access an element of a list using the index operator []. Suppose we have the following 
         declarations:
         *****************************************************************************/                                                                                 
        
        Integer w = 1, x = 2, y = 3, z = 4;
        IntegerList iL(w, x, y, z);
        
        /*****************************************************************************
         Then the statement
         *****************************************************************************/
        
        Integer c = iL[0];
        
        /*****************************************************************************
         assigns c the same value as w (which is 1). Here's the proof:
         *****************************************************************************/
        
        Print("c=", c);
        Print("w=", w);
        
        /*****************************************************************************
         The statement
         *****************************************************************************/
        
        c = iL[3];
        
        /*****************************************************************************
         assigns c the same value as z (which is 4). 
         *****************************************************************************/
        
        Print("Now c=", c);
        
        /*****************************************************************************
         The first element on a list is indexed by 0, and if a List has N elements, the last one is indexed 
         by N - 1.
         *****************************************************************************/
}