00001 #include "MusimatTutorial.h" 00002 MusimatTutorialSection(B0114) { 00003 Print("*** B.1.14 Accessing List Elements ***"); 00004 /***************************************************************************** 00005 00006 B.1.14 Accessing List Elements 00007 00008 We can access an element of a list using the index operator []. Suppose we have the following 00009 declarations: 00010 *****************************************************************************/ 00011 00012 Integer w = 1, x = 2, y = 3, z = 4; 00013 IntegerList iL(w, x, y, z); 00014 00015 /***************************************************************************** 00016 Then the statement 00017 *****************************************************************************/ 00018 00019 Integer c = iL[0]; 00020 00021 /***************************************************************************** 00022 assigns c the same value as w (which is 1). Here's the proof: 00023 *****************************************************************************/ 00024 00025 Print("c=", c); 00026 Print("w=", w); 00027 00028 /***************************************************************************** 00029 The statement 00030 *****************************************************************************/ 00031 00032 c = iL[3]; 00033 00034 /***************************************************************************** 00035 assigns c the same value as z (which is 4). 00036 *****************************************************************************/ 00037 00038 Print("Now c=", c); 00039 00040 /***************************************************************************** 00041 The first element on a list is indexed by 0, and if a List has N elements, the last one is indexed 00042 by N - 1. 00043 *****************************************************************************/ 00044 } 00045 00047 /* $Revision: 1.2 $ $Date: 2006/09/05 06:32:25 $ $Author: dgl $ $Name: $ $Id: B0114.cpp,v 1.2 2006/09/05 06:32:25 dgl Exp $ */ 00048 // The Musimat Tutorial � 2006 Gareth Loy 00049 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" � 2006 Gareth Loy 00050 // and published exclusively by The MIT Press. 00051 // This program is released WITHOUT ANY WARRANTY; without even the implied 00052 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00053 // For information on usage and redistribution, and for a DISCLAIMER OF ALL 00054 // WARRANTIES, see the file, "LICENSE.txt," in this distribution. 00055 // "Musimathics" is available here: http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916 00056 // Gareth Loy's Musimathics website: http://www.musimathics.com/ 00057 // The Musimat website: http://www.musimat.com/ 00058 // This program is released under the terms of the GNU General Public License 00059 // available here: http://www.gnu.org/licenses/gpl.txt 00060