1 / 18

Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making

Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making. Tutorial 4A Topics. Section A - Decision Making if statements if…else statements Nested if statements switch statements. Decision Making. Decision Making

bergeron
Télécharger la présentation

Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 4Decision Making with Control Structures and StatementsSection A - Decision Making JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  2. Tutorial 4A Topics • Section A - Decision Making • if statements • if…else statements • Nested if statements • switch statements JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  3. Decision Making • Decision Making • Process of determining the order in which statements execute in a program • AKA – flow control • Decision-Making Structures • Special type of JavaScript statements used for making decisions JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  4. Decision Making • if Statements • Used to execute specific programming code if the evaluation of a conditional expression returns a value of true • “Do this or don’t do this” • Syntax (3 primary parts) if (conditional_expression) { statement(s); } JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  5. Decision Making • if Statements • Operation • If the conditional expression is true, the statement(s) is/are executed • Control then continues to subsequent code • Command block • Multiple statements contained within a set of braces (require curly braces) JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  6. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  7. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  8. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  9. Decision Making • if Statements • Conditional Expression • Can consist of: • Comparison operators • Logical operators • Combination of the two • Must resolve to Boolean value JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  10. Decision Making • if…else Statements • Used to execute one set of code if the evaluation of a conditional expression returns a value of true, otherwise executes another set of code • “Do this or do something else” • Syntax if (conditional_expression) { statement(s); } else { statement(s); } JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  11. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  12. Decision Making • Nested if and if…else Statements • Nested statements • Statements contained within other statements • Syntax (variable) if (conditional_expression) { statement(s); if (conditional_expression) { statement(s); } } else { statement(s); } JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  13. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  14. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  15. Decision Making • switch Statements • Controls program flow by executing a specific set of statements, depending on the value of an expression • Syntax switch (expression) { case label1: statement(s); break; case label2: statement(s); break; default: statement(s); } JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  16. Decision Making • switch Statements • Case labels • Identify specific code segments • Can use a variety of data types as case labels • Break statement • Used to exit switch statements • Default label • Contains statements that execute when the condition expression doesn’t match any of the case labels JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  17. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

  18. JavaScript Tutorial 4 -Decision Making with Control Structures and Statements

More Related