• Main Page
  • Files
  • File List
  • File Members

/Users/garethloy/Musimathics/Musimat1.2/MusimatTutorial/B0109.cpp

Go to the documentation of this file.
00001 #include "MusimatTutorial.h"
00002 MusimatTutorialSection(B0109) {
00003         Print("*** B.1.9 Assignment ***");
00004         /*****************************************************************************
00005          
00006          B.1.9 Assignment
00007          
00008          We have already seen assignment, but here's a proper introduction.
00009          
00010          We can assign the value of an expression to a variable using the assignment operator =. For example,
00011          
00012          lhs = rhs;
00013          
00014          assigns the expression rhs to lhs. The object on the right-hand side of the = sign (i.e., rhs) can 
00015          be any expression. The object on the left-hand side (i.e., lhs) must be a variable name, with one 
00016          exception. For example, the statement
00017          *****************************************************************************/
00018          
00019          Integer s = 3 + 5;
00020         Print(s);
00021          
00022         /*****************************************************************************
00023          sets the value of Integer variable s to 8.
00024          
00025          The left-hand side of an assignment can also indicate that a certain element of a list is to receive 
00026          the value on the right-hand side. For example, here's an IntegerList:
00027          *****************************************************************************/
00028         
00029         IntegerList iL(10, 11, 12, 13);
00030         Print("Initial form of iL = ", iL);
00031         
00032         /*****************************************************************************
00033          The next statement replaces the second element on the list (counting from 0) with 100:
00034          *****************************************************************************/
00035         
00036         iL[2] = 100;
00037         
00038         /*****************************************************************************
00039          This causes the list to become
00040          
00041          (10, 11, 100, 13)
00042          
00043          Note that lists are indexed starting at 0.
00044          *****************************************************************************/
00045                 
00046         Print( "After replacement of 2nd element, iL=", iL );
00047         
00048 }
00049 
00051 /* $Revision: 1.2 $ $Date: 2006/09/05 06:32:25 $ $Author: dgl $ $Name:  $ $Id: B0109.cpp,v 1.2 2006/09/05 06:32:25 dgl Exp $ */
00052 // The Musimat Tutorial � 2006 Gareth Loy
00053 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" � 2006 Gareth Loy 
00054 // and published exclusively by The MIT Press.
00055 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00056 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00057 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00058 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00059 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00060 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00061 // The Musimat website:                 http://www.musimat.com/
00062 // This program is released under the terms of the GNU General Public License
00063 // available here:                      http://www.gnu.org/licenses/gpl.txt
00064 

Generated on Fri Nov 26 2010 16:18:25 for Musimat Tutorial by  doxygen 1.7.2