JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program. 2004 (3rd) edition. By Deitel, Deitel,

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.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
 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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
© 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.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 9 - JavaScript: Control Statements II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
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.
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.
Chapter 05 (Part III) Control Statements: Part II.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Spring 2005, Gülcihan Özdemir Dağ Lecture 5, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 5 Outline 5.0 Revisiting.
 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.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
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.
JavaScript, Fourth Edition
 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.
 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.
ECE122 Feb 10, Unary Operator An operator that takes only a single operand Plus: + Minus: – Cast: (type). E.g. (double)
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
Chapter 4 - Program Control
Chapter 15 - JavaScript/JScript: Control Structures II
JavaScript: Control Statements.
JavaScript: Control Statements I
JavaScript: Control Statements (II)
- Additional C Statements
Chapter 9 - JavaScript: Control Structures II
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 4 - Program Control
JavaScript: Control Statements II
Dale Roberts, Lecturer IUPUI
Chapter 4 - Program Control
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published by Prentice Hall. ISBN

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

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.

9.2 Essentials of Counter- Controlled Repetition Counter-controlled repetition –Name of a control –Initial value –Increment or decrement –Final value

WhileCounter.html (1 of 2)

9.3 for Repetition Statement for repetition statement –Handles all the details of counter-controlled repetition –for structure header The first line

ForCounter.html (1 of 1)

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.

9.4 Examples Using the for Statement Summation with for Compound interest calculation with for loop –Math object Method pow Method round

Sum.html (1 of 1)

Interest.html (1 of 2)

9.5 switch Multiple- Selection Statement Controlling expression Case labels Default case

SwitchTest.html (1 of 3)

SwitchTest.html (2 of 3)

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

DoWhileTest.html (1 of 2)

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

BreakTest.html (1 of 2)

ContinueTest.html (1 of 2)

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

BreakLabelTest.html (1 of 2)

ContinueLabelTest.html (1 of 2)

Logical operators

9.9 Logical Operators More logical operators –Logical AND ( && ) –Logical OR ( || ) –Logical NOT ( ! )

9.9 Logical Operators

LogicalOperators.html (1 of 2)

9.9 Logical Operators

Conclusion to JavaScript introduction

9.10 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

When things go wrong: Debugging JavaScript Taken from JavaScript is case sensitive –Document.write() will not work. Neither will document.Write(). Almost every object, property, and method name like document and write() begin with a lower case letter. In cases like document.bgColor the second word in an object, property, or method name is almost always capitalized. I.e. the C in bgColor but nothing else. Use the American spelling of color –There is no colour property. Don't forget the closing bracket, and don’t forget both quotes –Make sure your pairs of (parentheses) and “double quotes” or ‘single quotes’ all match Spelling counts –Drop the e in document and watch what happens. The order you do things in matters –If you set the background colour in the head of the document the document background colour may not change. If you set it in the body it will. Watch out for quotes inside quotes –Whenever you write out an HTML tag with an attribute that requires quotes you must escape the quote inside the tag by placing a backslash just before it. –For example document.write(" A LINK ") will produce an error. –Escaping the quotes will fix this: document.write(" A LINK "). –Make sure you escape both of them.

8.14 Web Resources international.org/publications/standards/Ecma-262.htmhttp:// international.org/publications/standards/Ecma-262.htm ef/javascript_index.htmlhttp:// ef/javascript_index.html developer.netscape.com/tech/javascript