4ProgramStructureIII

# 4ProgramStructureIII - Program Structure III Insertion of...

This preview shows pages 1–4. Sign up to view the full content.

(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 4. Program Structure III - 1 http://www.cs.cityu.edu.hk/~helena Program Structure III Program Structure III [Please switch off your phone] Insertion of Semicolons (;) Location of JavaScript Blocks Names of Variables and Functions Enclose statements in Braces { and } Assignment Statements Data Types (Numbers, Strings, Booleans) and Operations

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 4. Program Structure III - 2 http://www.cs.cityu.edu.hk/~helena The mystery of Semicolons (;) Semicolons ( ; ) are used to separate statements from each other. But manually adding semicolon is a common practice. (In Java, C .., adding semicolon is a must. Most programmers have adapted this rule already) Sometimes we get trouble if we handle line break or semicolon with mistake. Don’t rely on the automatic insertion of semicolons. ( An interesting discussion is available – see HOT questions at the course web ) a = 3 b = 4 ale rt(a+b) a = 3 ; b = 4 ; ale rt(a+b) ; //c alc ulate  ave rag e  o f m arks : var a =  ( pars e Int(do c um e nt.F1.C Mark.value ) + pars e Int(do c um e nt.F1.EMark.value ) + pars e Int(do c um e nt.F1.MMark.value )) / 3 ale rt(a) The fact: JavaScript automatically inserts semicolons if the line seems to be complete. a = 3 b = 4 a = 3 b = 4 a = 3; b = 4; //c alc ulate  ave rag e  o f m arks : var a =  ( pars e Int(do c um e nt.F1.C Mark.value ) + pars e Int(do c um e nt.F1.EMark.value ) + pars e Int(do c um e nt.F1.MMark.value )) / 3 ; ale rt(a) ; Can be omitted if each statement is on a separate line. But not suggested to omit!! Example: a = 3; b = 4; The invisible semicolons are automatically inserted.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern