This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ction to Computer Programming City Univ of HK / Dept of CS / Helena Wong http://www.cs.cityu.edu.hk/~helena 4. Program Structure III - 8 Assignment Statements
Right-hand-side Left-hand-side Assignment statement (=) : Assign a value to a variable (or object property, eg. innerHTML) Example: va r m s g , a ; m s g = " Ho w a re yo u ? " ; a = 1 0 0 ;
d o c um e nt.g e tEle m e ntById (`c h n') .inne rHT ML = `A'; d o c um e nt.F1 .re s ult.va lue = a + b ; We can also assign a value at the same time when a variable is declared: Example: va r x=4 , m s g =" Ho w a re yo u ? " ; More powerful assignment operators.
Example: s a la ry += 1 0 0 ; s a la ry = s a la ry + 1 0 0 ; are the same. c o unte r += 1 ; counter=counter+1; are the same. Similar ones are : -=, *=, /=, %=
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong http://www.cs.cityu.edu.hk/~helena 4. Program Structure III - 9 Data Types Data Types: the types of values that can be handled in a programming
language. 3 J...
View Full Document
This note was uploaded on 03/10/2012 for the course CS 1301 taught by Professor Dr.wong during the Winter '08 term at City University of Hong Kong.
- Winter '08
- Computer Programming