00001 #include "MusimatTutorial.h" 00002 MusimatTutorialSection(B0109) { 00003 Print("*** B.1.9 Assignment ***"); 00004 /***************************************************************************** 00005 00006 B.1.9 Assignment 00007 00008 We can assign the value of an expression to a variable using the assignment operator =. For example, 00009 00010 lhs = rhs; 00011 00012 assigns the expression rhs to lhs. The object on the right-hand side of the = sign (i.e., rhs) can 00013 be any expression. The object on the left-hand side (i.e., lhs) must be a variable name, with one 00014 exception. For example, the statement 00015 00016 s = 3 + 5; 00017 00018 sets the value of variable s to 8. 00019 00020 The left-hand side of an assignment can also indicate that a certain element of a list is to receive 00021 the value on the right-hand side. For example, 00022 *****************************************************************************/ 00023 00024 IntegerList iL(0, 1, 2, 3); 00025 00026 iL[2] = 10; 00027 00028 /***************************************************************************** 00029 replaces the third element with 10, causing the list to become 00030 00031 {0, 1, 10, 3} 00032 00033 Note that lists are indexed starting at 0. So writing 00034 *****************************************************************************/ 00035 00036 iL[0] = 55; 00037 00038 /***************************************************************************** 00039 causes the list to be {55, 1, 10, 3} which we can see by printing it: 00040 *****************************************************************************/ 00041 00042 Print( iL ); 00043 00044 }} 00045 00047 /* $Revision: 1.2 $ $Date: 2006/09/09 06:23:07 $ $Author: dgl $ $Name: $ $Id: _b0109_8cpp-source.html,v 1.2 2006/09/09 06:23:07 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
1.4.7