 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.

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter4: Control Statements Part I.
 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.
Chapter 3 - Structured Program Development
 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.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structure.
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.
 2007 Pearson Education, Inc. All rights reserved Structured Program Development in C.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
Fall 2008Yanjun Li CSRU JavaScript: Control Statements I Internet & World Wide Web:
 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.
Structured Program Development in C
Lecture 3 Structured Program Development in C
 2002 Prentice Hall. All rights reserved. 1 Chapter 3 – Control Structures Outline 3.1 Introduction 3.2 Algorithms 3.3 Pseudocode 3.4Control Structures.
 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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Spring 2005, Gülcihan Özdemir Dağ Lecture 3, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 3 Outline 3.1 Introduction.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4: Control Structures: Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
C Lecture Notes 1 Structured Program Development.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
1 C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved. 4.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
 2007 Pearson Education, Inc. All rights reserved Structured Program Development in C.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Control Structures Outline -Introduction -Algorithms -Pseudocode -Control Structures -if Selection Structure.
C Programming 2002 Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 17 - WMLScript: Control Structures I Outline 17.1 Introduction 17.2 Algorithms 17.3 Pseudocode.
 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.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 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 Lecture 3 Control Structures else/if and while.
Chapter 3 Structured Program Development Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
1 JavaScript/Jscript 2 Control Structures I. 2 Introduction Before programming a script have a –Thorough understanding of problem –Carefully planned approach.
 2007 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. 1 Chapter 3 - Structured Program Development Outline.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
 2007 Pearson Education, Inc. All rights reserved Structured Program Development in C.
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
Algorithm: procedure in terms of
JavaScript: Control Statements I
Chapter 8 - 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 - Structured Program Development
EPSII 59:006 Spring 2004.
Chapter 8 - JavaScript: Control Structures I
Structural Program Development: If, If-Else
Presentation transcript:

 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 Control Structures 8.5 if Selection Statement 8.6 if…else Selection Statement 8.7 while Repetition Statement 8.8 Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) 8.9 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) 8.10 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) 8.11 Assignment Operators 8.12 Increment and Decrement Operators 8.13 Note on Data Types 8.14 Web Resources

 2003 Prentice Hall, Inc. All rights reserved. Objectives In this lesson, you will learn: –To understand basic problem-solving techniques. –To be able to develop algorithms through the process of top- down, stepwise refinement. –To be able to use the if and if … else selection statements to choose among alternative actions. –To be able to use the while repetition statement to execute statements in a script repeatedly. –To understand counter-controlled repetition and sentinel- controlled repetition. –To be able to use the increment, decrement and assignment operators.

 2003 Prentice Hall, Inc. All rights reserved. 8.1 Introduction Writing a script –Thorough understanding of problem –Carefully planned approach –Understand the types of building blocks that are available –Employ proven program-construction principles

 2003 Prentice Hall, Inc. All rights reserved. 8.2 Algorithms Actions to be executed Order in which the actions are to be executed

 2003 Prentice Hall, Inc. All rights reserved. 8.3 Pseudocode Artificial Informal Helps programmers develop algorithms

 2003 Prentice Hall, Inc. All rights reserved. 8.4 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 Three control structures –Sequence structure –Selection structure if if … else switch –Repetition structure while do … while for for … in

 2003 Prentice Hall, Inc. All rights reserved. 8.4 Control Structures Flowchart –Graphical representation of algorithm or portion of algorithm –Flowlines Indicate the order the actions of the algorithm execute –Rectangle symbol Indicate any type of action –Oval symbol A complete algorithm –Small circle symbol A portion of algorithm –Diamond symbol Indicates a decision is to be made

 2003 Prentice Hall, Inc. All rights reserved. 8.4 Control Structures add grade to total total = total + grade; add 1 to counter counter = counter +1; Fig. 8.1Flowcharting JavaScript’s sequence structure.

 2003 Prentice Hall, Inc. All rights reserved. 8.4 Control Structures

 2003 Prentice Hall, Inc. All rights reserved. 8.5 if Selection Statement Single-entry/single-exit structure Indicate action only when the condition evaluates to true

 2003 Prentice Hall, Inc. All rights reserved. 8.5 if Selection Statement grade >= 60 true false print “Passed” Fig. 8.3Flowcharting the single-selection if statement.

 2003 Prentice Hall, Inc. All rights reserved. 8.6 if…else Selection Statement Indicate different actions to be perform when condition is true or false Conditional operator ( ?: ) –JavaScript’s only ternary operator Three operands Forms a conditional expression Dangling-else problem

 2003 Prentice Hall, Inc. All rights reserved. 8.6 if…else Selection Statement grade >= 60 true print “Failed” false print “Passed” Fig. 8.4Flowcharting the double-selection if … else statement.

 2003 Prentice Hall, Inc. All rights reserved. 8.7 while Repetition Statement Repetition structure (loop) –Repeat action while some condition remains true

 2003 Prentice Hall, Inc. All rights reserved. 8.7 while Repetition Statement product <= 1000 product = 2 * product true false Fig. 8.5Flowcharting the while repetition statement.

 2003 Prentice Hall, Inc. All rights reserved. 8.8 Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) Counter-controlled repetition –Counter Control the number of times a set of statements executes –Definite repetition

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline average.html (1 of 3)

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline average.html (2 of 3)

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline average.html (3 of 3)

 2003 Prentice Hall, Inc. All rights reserved. 8.9 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) Indefinite repetition –Sentinel value

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline average2.html (1 of 3)

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline average2.html (2 of 3)

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline average2.html (3 of 3)

 2003 Prentice Hall, Inc. All rights reserved.

8.10 Formulating Algorithms with Top- Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) Consider problem Make observations Top-down, stepwise refinement

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline analysis.html (1 of 2)

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline analysis.html (2 of 2)

 2003 Prentice Hall, Inc. All rights reserved.

8.11 Assignment Operators Compound assignment operators –Abbreviate assignment expressions

 2003 Prentice Hall, Inc. All rights reserved Assignment Operators

 2003 Prentice Hall, Inc. All rights reserved Increment and Decrement Operators Preincrement or predecrement operator –Increment of decrement operator placed before a variable Postincrement or postdecrement operator –Increment of decrement operator placed after a variable

 2003 Prentice Hall, Inc. All rights reserved Increment and Decrement Operators

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline increment.html (1 of 2)

 2003 Prentice Hall, Inc. All rights reserved. Outline  2003 Prentice Hall, Inc. All rights reserved. Outline increment.html (2 of 2)

 2003 Prentice Hall, Inc. All rights reserved Increment and Decrement Operators

 2003 Prentice Hall, Inc. All rights reserved Note on Data Types Loosely typed –Automatically converts between values of different types

 2003 Prentice Hall, Inc. All rights reserved Web Resources developer.netscape.com/tech/javascript