Ch 7: JavaScript Control Statements I.

Slides:



Advertisements
Similar presentations
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 4 Client Side Scripting JavaScript Looping.
Advertisements

 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Chapter 04 (Part III) Control Statements: Part I.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 Control structures  Algorithm & flowchart  If statements  While statements.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Outline 14.1Introduction 14.2Algorithms 14.3Pseudocode 14.4Control Structures 14.5The if Selection.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection Statement 4.6 if else Selection Statement 4.7 while.
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Structured Program Development in C
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
The University of Texas – Pan American
 2003 Prentice Hall, Inc. All rights reserved.  2004 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
C Lecture Notes 1 Structured Program Development.
C++ Programming Lecture 6 Control Structure II (Repetition) By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Dale Roberts Program Control using Java - Repetition Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Control Structures: Part 1.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
1 JavaScript/Jscript 2 Control Structures I. 2 Introduction Before programming a script have a –Thorough understanding of problem –Carefully planned approach.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
Chapter 14 - JavaScript/JScript: Control Structures I
Chapter 7 JavaScript: Control Statements, Part 1
while Repetition Structure
Control Statements: Part 1
JavaScript: Control Statements I
Chapter 8 - JavaScript: Control Statements I
Chapter 4 – Control Structures Part 1
JavaScript: Control Statements.
JavaScript: Control Statements I
Chapter 8 - JavaScript: Control Structures I
MSIS 655 Advanced Business Applications Programming
Structured Program
Chapter 3 - Structured Program Development
3 Control Statements:.
Chapter 3 – Control Structures
Chapter 3 - Structured Program Development
2.6 The if/else Selection Structure
Chapter 4 - Control Structures: Part 1
EPSII 59:006 Spring 2004.
Chapter 8 - JavaScript: Control Structures I
Presentation transcript:

Ch 7: JavaScript Control Statements I

7.4 Control Structures Sequential execution Transfer of control Execute statements in the order they appear in the code Transfer of control Changing the order in which statements execute All programs can be written in terms of only three control structures sequence selection repetition

7.4 Control Structures (Cont.) JavaScript provides three selection structures. The if statement called a single-selection structure because it selects or ignores a single action or group of actions. The if…else statement, a double-selection structure because it selects between two different actions or group of actions. The switch statement, multiple-selection structure because it selects among many different actions or groups of actions.

Fig. 7.3 | Flowcharting the single-selection if statement. If grade >= 60, execute this statement Otherwise Fig. 7.3 | Flowcharting the single-selection if statement.

Fig. 7.4 | Flowcharting the double-selection if else statement. If the condition is met… Otherwise… This is executed This is executed Fig. 7.4 | Flowcharting the double-selection if else statement.

7.4 Control Structures (Cont.) JavaScript provides four repetition statements, namely, while do…while for for…in Keywords cannot be used as identifiers (e.g., for variable names).

Fig. 7.2 | JavaScript keywords.

7.7 while Repetition Statement Allows the programmer to specify that an action is to be repeated while some condition remains true The body of a loop may be a single statement or a block Eventually, the condition becomes false and repetition terminates

Fig. 7.5 | Flowcharting the while repetition statement. And evaluate if this statement is still true Break out of the cycle when the statement is false If this statement is true… Execute this statement… Fig. 7.5 | Flowcharting the while repetition statement.

Fig. 7.7 | Counter-controlled repetition to calculate a class average (Part 1 of 3). Stores the sum of grades Sets total to 0 Sets gradeCounter to 1 in preparation for the loop Continues the cycle until gradeCounter is greater than 10

Fig. 7.7 | Counter-controlled repetition to calculate a class average (Part 2 of 3). Increments gradeCounter by 1 after each iteration of the loop

Fig. 7.7 | Counter-controlled repetition to calculate a class average (Part 3 of 3).

7.9 Formulating Algorithms: Sentinel-Controlled Repetition Special value called a sentinel value (also called a signal value, a dummy value or a flag value) indicates the end of data entry Often is called indefinite repetition, because the number of repetitions is not known in advance Choose a sentinel value that cannot be confused with an acceptable input value

Fig. 7.9 | Sentinel-controlled repetition to calculate a class average (Part 1 of 3). Set gradeCounter to 0 in preparation for the loop

Executes until gradeValue equals -1 Fig. 7.9 | Sentinel-controlled repetition to calculate a class average (Part 2 of 3). Increments gradeCounter by 1 after each iteration of the loop Begin new control structure Execute if the condition in the if statement is not satisfied

Fig. 7.9 | Sentinel-controlled repetition to calculate a class average (Part 3 of 3).