CLASS NOTES:
SD110 Computer Programming Logic
 
 

 

EXPRESSIONS VS. STATEMENTS
 
 
OVERVIEW:
 
   


The simplest difference I see between an Expression and a Statement is that Expressions calculate something, and Statements merely state that something has a particular value. Any value which is calculated is an Expression. X+5 is an expression, X=5 is a Statement.

When you see the '=' sign in programming it does not mean the same thing as it does in Math.
In programming it means that whatever the value is to the right of the equal sign,
is now to be placed into the Variable Name on the left side of the equal sign.

In Math
Payroll = Payroll + $40.00 could not be true.
(Something numeric cannot have the same value as itself plus any non 0 value.)

But in Programming
Payroll = Payroll + 40 means that you caculate the value of Payroll + 40
and place that value into the memory location known as Payroll.
(The value of what is to the right of the = goes into the Variable on the left.)

So is Payroll = Payroll + 40 a Statement or an Expression?

   
     
 
BACK