JavaScript: Control Statements (II)

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.
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.
 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.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
 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.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
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.
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.
 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.
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.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
 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.
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
JavaScript: Control Structures I
Chapter 6: Loops.
Chapter 5- Control Structures: Part 2
Chapter 4 C Program Control Part II
Control Statements: Part 2
Control Structures: Part 2
Chapter 4 - Program Control
Chapter 15 - JavaScript/JScript: Control Structures II
CiS 260: App Dev I Chapter 4: Control Structures II.
Ch 7: JavaScript Control Statements I.
Chapter 2.2 Control Structures (Iteration)
JavaScript: Control Statements.
JavaScript: Control Statements I
JavaScript: Control Statements II
Programming Fundamentals Lecture #6 Program Control
MSIS 655 Advanced Business Applications Programming
- Additional C Statements
Chapter 9 - JavaScript: Control Structures II
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 4 - Program Control
for, do-while and switch statments
Program Control Topics While loop For loop Switch statement
Chapter 2.2 Control Structures (Iteration)
Chapter 6 Control Statements: Part 2
JavaScript: Control Statements II
Dale Roberts, Lecturer IUPUI
Chapter 4 - Program Control
PROGRAM FLOWCHART Iteration Statements.
Chapter 8 JavaScript: Control Statements, Part 2
Control Statements:.
Presentation transcript:

JavaScript: Control Statements (II) Outline 1. Essentials of Counter-Controlled Repetition 2. for Repetition Statement 3. Examples Using the for Statement 4. switch Multiple-Selection Statement 5. do…while Repetition Statement 6. break and continue Statements

In this lesson, you will learn: 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.

1. Essentials of Counter-Controlled Repetition Name of a control Initial value Increment or decrement Final value

WhileCounter.html (1 of 2)

WhileCounter.html (2 of 2)

2. for Repetition Statement Handles all the details of counter-controlled repetition for structure header The first line

ForCounter.html (1 of 1)

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

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

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

12.3 Math Object

12.3 Math Object

Sum.html (1 of 1)

Interest.html (1 of 2)

Interest.html (2 of 2)

4. switch Multiple-Selection Statement Controlling expression Case labels Default case

SwitchTest.html (1 of 3)

SwitchTest.html (2 of 3)

SwitchTest.html (3 of 3)

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

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)

DoWhileTest.html (2 of 2)

5. do…while Repetition Structure action(s) true condition false Fig. 9.10 do…while repetition statement flowchart.

6. break and continue Statements 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)

BreakTest.html (2 of 2)

ContinueTest.html (1 of 2)

ContinueTest.html (2 of 2)