Functions

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

#include "MusimatTutorial.h"

Go to the source code of this file.

Functions

 MusimatTutorialSection (B0109)

Function Documentation

MusimatTutorialSection ( B0109   )

Definition at line 2 of file B0109.cpp.

                              {
        Print("*** B.1.9 Assignment ***");
        /*****************************************************************************
         
         B.1.9 Assignment
         
         We have already seen assignment, but here's a proper introduction.
         
         We can assign the value of an expression to a variable using the assignment operator =. For example,
         
         lhs = rhs;
         
         assigns the expression rhs to lhs. The object on the right-hand side of the = sign (i.e., rhs) can 
         be any expression. The object on the left-hand side (i.e., lhs) must be a variable name, with one 
         exception. For example, the statement
         *****************************************************************************/
         
         Integer s = 3 + 5;
        Print(s);
         
        /*****************************************************************************
         sets the value of Integer variable s to 8.
         
         The left-hand side of an assignment can also indicate that a certain element of a list is to receive 
         the value on the right-hand side. For example, here's an IntegerList:
         *****************************************************************************/
        
        IntegerList iL(10, 11, 12, 13);
        Print("Initial form of iL = ", iL);
        
        /*****************************************************************************
         The next statement replaces the second element on the list (counting from 0) with 100:
         *****************************************************************************/
        
        iL[2] = 100;
        
        /*****************************************************************************
         This causes the list to become
         
         (10, 11, 100, 13)
         
         Note that lists are indexed starting at 0.
         *****************************************************************************/
                
        Print( "After replacement of 2nd element, iL=", iL );
        
}