lecture18

lecture18 - PIC 40A Lecture 18 JavaScript Control...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 40A Lecture 18: JavaScript Control Statements, Conversions, Variable Scope, JSEE
Background image of page 1

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

View Full Document Right Arrow Icon
Control Statements • A program’s flow is the order of execution of the program’s statements. Control statements determine flow based on values of control expressions or conditions. Examples of control statements: – selection statements • if-then, if-then-else, switch – loop statements • while, do-while, for, for-in
Background image of page 2
Control Expressions Control expressions can be either • primitive values • relational expressions • function calls • object references • compound expressions formed with any of the above by using logical operators such as ! && || • Anything that is or can be coerced to a Boolean primitive value
Background image of page 3

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

View Full Document Right Arrow Icon
How non-Booleans are interpreted in a condition • If a String, then true unless empty “” or “0” • If a Number, then true unless it is 0 • If an object reference, then true unless null • If undefined, then false.
Background image of page 4
Selection Statements • if-then-else – makes a decision on which compound statement to execute based on a condition if( conexpr ) { /* execute this when conexpr true */ } else { /* execute this when conexpr false */ } Note: Can omit else clause like in C++ to make if-then.
Background image of page 5

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

View Full Document Right Arrow Icon
Selection Statements switch statement executes a compound statement based on the value of a control expression control goes to the statement whose case value
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 20

lecture18 - PIC 40A Lecture 18 JavaScript Control...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online