 2004 Prentice Hall, Inc. All rights reserved. Chapter 9 - JavaScript: Control Statements II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.

Slides:



Advertisements
Similar presentations
Session 5 JavaScript/JScript: Control Structures II Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Advertisements

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Chapter 5: Control Structures II (Repetition)
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structures: continued.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
 2002 Prentice Hall. All rights reserved. 1 Chapter 3 – Control Structures Outline 3.1 Introduction 3.2 Algorithms 3.3 Pseudocode 3.4Control Structures.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved The switch Multiple-Selection Statement switch.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
 2003 Prentice Hall, Inc. All rights reserved.  2004 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1.
1 Lecture 4 for loops and switch statements Essentials of Counter-Controlled Repetition Counter-controlled repetition requires  Name of control.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
1 4.8The do/while Repetition Structure The do/while repetition structure –Similar to the while structure –Condition for repetition tested after the body.
Algorithm and Programming Branching Algorithm & C Program Control Dr. Ir. Riri Fitri Sari MM MSc International Class Electrical Engineering Dept University.
C Program Control Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1 Introduction 5.2 Essentials of Counter-Controlled.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (Switch, do-while, break) Outline 4.7The.
Chapter 4 C Program Control. Objectives In this chapter, you will learn: –To be able to use the for and do … while repetition statements. –To understand.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 18 - WMLScript: Control Structures II Outline 18.1 Introduction 18.2 Essentials of Counter-Controlled.
University of Palestine software engineering department Introduction to data structures Control Statements: Part 1 instructor: Tasneem Darwish.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
 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.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Java™ How to Program, Early Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1 Introduction 5.2 Essentials of Counter-Controlled.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Essentials of Counter-Controlled Repetition Counter-controlled repetition requires: Control variable (loop counter) Initial value of the control variable.
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 9 - JavaScript: Control Statements II
Chapter 4 – C Program Control
Control Statements: Part 2
Chapter 4 - Program Control
Chapter 15 - JavaScript/JScript: Control Structures II
JavaScript: Control Statements.
JavaScript: Control Statements (II)
Chapter 9 - JavaScript: Control Structures II
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 4 - Program Control
JavaScript: Control Statements II
Chapter 4 - Program Control
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

 2004 Prentice Hall, Inc. All rights reserved. Chapter 9 - JavaScript: Control Statements II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled Repetition 9.3 for Repetition Statement 9.4 Examples Using the for Statement 9.5 switch Multiple-Selection Statement 9.6 do … while Repetition Statement 9.7 break and continue Statements 9.8 Labeled break and continue Statements 9.9 Logical Operators 9.10 Summary of Structured Programming 9.11Web Resources

 2004 Prentice Hall, Inc. All rights reserved. Objectives In this lesson, you will learn: –To be able to use the for and do … while repetition statements to execute statements in a program repeatedly. –To understand multiple selection using the switch selection statement. –To be able to use the break and continue program-control statements. –To be able to use the logical operators.

 2004 Prentice Hall, Inc. All rights reserved. 9.1 Introduction Continuation of Chapter 8 –Theory and principles of structured programming

 2004 Prentice Hall, Inc. All rights reserved. 9.2 Essentials of Counter-Controlled Repetition Counter-controlled repetition –Name of a control –Initial value –Increment or decrement –Final value

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

 2004 Prentice Hall, Inc. All rights reserved. Outline WhileCounter.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. 9.3 for Repetition Statement for repetition statement –Handles all the details of counter-controlled repetition –for structure header The first line

 2004 Prentice Hall, Inc. All rights reserved. Outline ForCounter.html (1 of 1)

 2004 Prentice Hall, Inc. All rights reserved.

9.3 for Repetition Statement for (var counter =1; counter <=7; ++counter ) Initial value of control variable Increment of control variable Control variable name Final value of control variable for which the condition is true for keyword Loop-continuation condition Fig. 9.3 for statement header components.

 2004 Prentice Hall, Inc. All rights reserved. 9.3 for Repetition Statement counter <=7 document.writeln( "<p style=\"font-size: " + counter + "ex\">XHTML font size " + counter +"ex " ); true false var counter =1 ++counter Establish initial value of control variable. Determine if final value of control variable has been reached. Body of loop (this may be many statements) Increment the control variable. Fig. 9.4 for repetition structure flowchart.

 2004 Prentice Hall, Inc. All rights reserved. 9.4 Examples Using the for Statement Summation with for Compound interest calculation with for loop –Math object Method pow Method round

 2004 Prentice Hall, Inc. All rights reserved. Outline Sum.html (1 of 1)

 2004 Prentice Hall, Inc. All rights reserved.

Outline Interest.html (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline Interest.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. 9.5 switch Multiple-Selection Statement Controlling expression Case labels Default case

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

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

 2004 Prentice Hall, Inc. All rights reserved. Outline SwitchTest.html (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved.

9.5 switch Multiple-Selection Statement case a a action(s) true false... break case b action(s) break false case z z action(s) break default action(s) true case b

 2004 Prentice Hall, Inc. All rights reserved. 9.6 do … while Repetition Statement Similar to the while statement Tests the loop continuation condition after the loop body executes Loop body always executes at least once

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

 2004 Prentice Hall, Inc. All rights reserved. Outline DoWhileTest.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. 9.6 do…while Repetition Structure condition true action(s) false Fig do … while repetition statement flowchart.

 2004 Prentice Hall, Inc. All rights reserved. 9.7 break and continue Statements break –Immediate exit from the structure –Used to escape early from a loop –Skip the remainder of a switch statement continue –Skips the remaining statements in the body of the structure –Proceeds with the next iteration of the loop

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

 2004 Prentice Hall, Inc. All rights reserved. Outline BreakTest.html (2 of 2)

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

 2004 Prentice Hall, Inc. All rights reserved. Outline ContinueTest.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. 9.8 Labeled break and continue Statements Labeled break statement –Break out of a nested set of structures –Immediate exit from that structure and enclosing repetition structures –Execution resumes with first statement after enclosing labeled statement Labeled continue statement –Skips the remaining statements in structure’s body and enclosing repetition structures –Proceeds with next iteration of enclosing labeled repetition structure –Loop-continuation test evaluates immediately after the continue statement executes

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

 2004 Prentice Hall, Inc. All rights reserved. Outline BreakLabelTest.html (2 of 2)

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

 2004 Prentice Hall, Inc. All rights reserved. Outline ContinueLabelTest.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. 9.9 Logical Operators More logical operators –Logical AND ( && ) –Logical OR ( || ) –Logical NOT ( ! )

 2004 Prentice Hall, Inc. All rights reserved. 9.9 Logical Operators

 2004 Prentice Hall, Inc. All rights reserved. 9.9 Logical Operators

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

 2004 Prentice Hall, Inc. All rights reserved. Outline LogicalOperators.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved.

9.9 Logical Operators

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming Flowcharts –Reveal the structured nature of programs Single-entry/single-exit control structures –Only one way to enter and one way to exit each control structure Control structure stacking –The exit point of one control structure is connected to the entry point of the next control structure

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming T F w h i l e statement T F f o r T F d o … w h i l e R e p e t i t i o n Fig. 9.20Single-entry/single-exit sequence, selection and repetition structures. (1 of 3) statement

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming b r e a k T F i f statement ( s i n g l e s e l e c t i o n ) T F i f … e l s e ( d o u b l e s e l e c t i o n ) T F s w i t c h ( m u l t i p l e s e l e c t i o n ) T F T F... S e l e c t i o n b r e a k b r e a k Fig. 9.20Single-entry/single-exit sequence, selection and repetition structures. (2 of 3) statement

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming Fig. 9.20Single-entry/single-exit sequence, selection and repetition structures. (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming Fig. 9.22Simplest flowchart.

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming Fig. 9.23Repeatedly applying rule 2 of Fig to the simplest flowchart.

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming Fig. 9.24Applying rule 3 of Fig to the simplest flowchart.

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming Stacked building blocksNested building blocks Overlapping building blocks (Illegal in structured programs) Fig. 9.25Stacked, nested and overlapped building blocks.

 2004 Prentice Hall, Inc. All rights reserved Summary of Structured Programming Fig. 9.26Unstructured flowchart.