JavaScript: Control Statements II

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Session 5 JavaScript/JScript: Control Structures II Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
 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.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
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.
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.
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.
University of Palestine software engineering department Introduction to data structures Control Statements: Part 1 instructor: Tasneem Darwish.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
 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.
Sections 5.1 – 5.4 © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Overview Go over parts of quiz? Another iteration structure for loop.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
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.

Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Chapter 4 Control Statements: Part 2
Chapter 9 - JavaScript: Control Statements II
Chapter 4 – C Program Control
Chapter 4 C Program Control Part I
Lecture 7: Repeating a Known Number of Times
JavaScript: Control Statements I
Chapter 5: Repetition Structures
Ch 7: JavaScript Control Statements I.
JavaScript: Control Statements.
JavaScript: Control Statements I
JavaScript: Control Statements II
Chapter 5- part 2 Control Statements: Loops 2
Arrays, For loop While loop Do while loop
Loop Control Structure.
Programming Fundamentals Lecture #6 Program Control
JavaScript: Control Statements (II)
MSIS 655 Advanced Business Applications Programming
Chapter 8 JavaScript: Control Statements, Part 2
Structured Program Development in C
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Chapter 4 - Program Control
3 Control Statements:.
Chapter 5 Control Statements: Loops 2
Chapter 6 Control Statements: Part 2
PROGRAM FLOWCHART Iteration Statements.
Chapter 8 JavaScript: Control Statements, Part 2
Control Statements:.
Presentation transcript:

JavaScript: Control Statements II

8.2 Essentials of Counter-Controlled Repetition Counter-controlled repetition requires name of a control variable initial value of the control variable the increment (or decrement) by which the control variable is modified each time through the loop the condition that tests for the final value of the control variable to determine whether looping should continue

Fig. 8.1 | Counter-controlled repetition (Part 1 of 2). Initializes counter Precedes the “ with a \ to create an escape sequence so that it can be used in the string Condition to be fulfilled with every iteration Incrementing statement

Fig. 8.1 | Counter-controlled repetition (Part 2 of 2).

8.3 for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable Can use a block to put multiple statements into the body for statement takes three expressions Initialization Condition Increment Expression

Fig. 8.2 | Counter-controlled repetition with the for statement (Part 1 of 2). Initial value of the control variable Condition to test whether looping should continue Increment to occur after each iteration of the loop Statement inside the for loop

Fig. 8.2 | Counter-controlled repetition with the for statement (Part 2 of 2).

8.4 Examples Using the for Statement JavaScript does not include an exponentiation operator Math object’s pow method for this purpose. Math.pow(x, y) calculates the value of x raised to the yth power. Floating-point numbers can cause trouble as a result of rounding errors

Fig. 8.6 | Compound interest calculation with a for loop (Part 1 of 2).

Fig. 8.6 | Compound interest calculation with a for loop (Part 2 of 2). Control variable year begins with a value of 1 Continue to execute the loop while year is less than or equal to 10 After each loop iteration, increase the value of year by 1

8.6 do…while Repetition Statement do…while statement tests the loop-continuation condition after the loop body executes The loop body always executes at least once

Fig. 8.9 | Using the do while repetition statement (Part 1 of 2). Perform the following actions… Then check to see if counter <= 6. If it is, iterate through the loop again.

Fig. 8.9 | Using the do while repetition statement (Part 2 of 2).