Fall 2008Yanjun Li CSRU2350 1 JavaScript: Control Statements I Internet & World Wide Web:

Slides:



Advertisements
Similar presentations
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Advertisements

 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 Control structures  Algorithm & flowchart  If statements  While statements.
14/11/11.  These words have special meanings in themselves  These should NOT be used as Identifiers.  For example:  Break, do, function, case, else,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
 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.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structure.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
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.
 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
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved The switch Multiple-Selection Statement switch.
 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.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
1 CSCE 1030 Computer Science 1 Control Statements in Java.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
 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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.
 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.
 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.
1 JavaScript: Control Structures. 2 Control Structures Flowcharting JavaScript’s sequence structure.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
1 JavaScript/Jscript 2 Control Structures I. 2 Introduction Before programming a script have a –Thorough understanding of problem –Carefully planned approach.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
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.
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 14 - JavaScript/JScript: Control Structures I
Chapter 7 JavaScript: Control Statements, Part 1
- Standard C Statements
JavaScript: Control Statements I
Chapter 8 - JavaScript: Control Statements I
Ch 7: JavaScript Control Statements I.
Lecturer CS & IT Department UOS MBDIN
JavaScript: Control Statements.
JavaScript: Control Statements I
Chapter 8 - JavaScript: Control Structures I
MSIS 655 Advanced Business Applications Programming
Structured Program
3 Control Statements:.
Dale Roberts, Lecturer IUPUI
Chapter 8 - JavaScript: Control Structures I
Presentation transcript:

Fall 2008Yanjun Li CSRU JavaScript: Control Statements I Internet & World Wide Web:

Fall 2008Yanjun Li CSRU Control Structures Sequential execution – Statements execute in the order they are written Transfer of control – Next statement to execute may not be the next one in sequence add grade to total total = total + grade; add 1 to counter counter = counter + 1;

Fall 2008Yanjun Li CSRU Boolean Expression Using Equality Operators – x = = y – x != y Using Relational Operators – x > y – x < y – x >= y – x <= y The value of the expression is either true or false

Fall 2008Yanjun Li CSRU if Selection Statement (1) Indicate action only when the condition evaluates to true JavaScript Format: if if ( boolean expression ) statement; Example: if if (grade>= 60) document.writeln(“Passed”); grade >= 60 true false print “Passed”

Fall 2008Yanjun Li CSRU if Selection Statement (2) Multiple actions are performed when the condition is true JavaScript Format: if if ( boolean expression ) { statementOne; statementTwo; : } Example: if if (grade>= 60) { document.writeln(" " + "Congratulations! "); document.writeln(" You Passed! "); }

Fall 2008Yanjun Li CSRU if…else Selection Statement (1) Indicate different actions to be perform when condition is true or false grade >= 60 true print “Failed” false print “Passed”

Fall 2008Yanjun Li CSRU if…else Selection Statement (2) JavaScript Format: if if ( boolean expression ) statement;else JavaScript Example : if ( grade >= 60 ) document.writeln(“Passed”); else document.writeln(“Failed”);

Fall 2008Yanjun Li CSRU if…else Selection Statement (3) Multiple actions JavaScript Format : if if ( boolean expression ) { statementOne; statementTwo; : }else { statementThree; statementFour; : }

Fall 2008Yanjun Li CSRU while Repetition Statement (1) Repetition structure (loop) – Repeat action while some condition remains true. product <= 1000 product = 2 * product true false

Fall 2008Yanjun Li CSRU while Repetition Statement (2) JavaScript Format : initialization; while while ( boolean expression ) { statement; update; } JavaScript Example : var product=2; while ( product <= 1000 ) { document.writeln(product); product = 2 * product; }

Fall 2008Yanjun Li CSRU Counter-Controlled Repetition Counter-controlled repetition – Counter Control the number of times a set of statements executes – Definite repetition

Fall 2008Yanjun Li CSRU average.html (1 of 3)

Fall 2008Yanjun Li CSRU average.html (2 of 3)

Fall 2008Yanjun Li CSRU

Fall 2008Yanjun Li CSRU Sentinel-Controlled Repetition Indefinite repetition – Sentinel value

Fall 2008Yanjun Li CSRU average2.html (1 of 3)

Fall 2008Yanjun Li CSRU average2.html (2 of 3)

Fall 2008Yanjun Li CSRU average2.html (3 of 3)

Fall 2008Yanjun Li CSRU

Fall 2008Yanjun Li CSRU Note on Data Types Loosely typed – Automatically converts between values of different types

Fall 2008Yanjun Li CSRU Web Resources developer.netscape.com/tech/javascript

Fall 2008Yanjun Li CSRU Reference Reproduced from the PowerPoints for Internet & World Wide Web How to Program, 3e by Deitel, Deitel and Goldberg © Reproduced by permission of Pearson Education, Inc.