Chapter 9: Control Statements II CIS 275—Web Application Development for Business I.

Slides:



Advertisements
Similar presentations
© 2007 Lawrenceville Press Slide 1 Chapter 5 The if Statement  Conditional control structure, also called a decision structure  Executes a set of statements.
Advertisements

1 JavaScript: Control Structures II. 2 whileCounter.html 1 2
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Control Structures Nested ifs, switch statements.
Session 5 JavaScript/JScript: Control Structures II Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 3 Control Structures.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structures: continued.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
 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.
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
Computers and Scientific Thinking David Reed, Creighton University Functions and Randomness 1.
Advanced Decisions and Loops Chapter Some Simple Schoolroom Statistics.
Client-Side programming with JavaScript 3
Arrays and Control Structures CST 200 – JavaScript 2 –
 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.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
 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.
C Program Control Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
CIS 375—Web App Dev II JavaScript II.
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,
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
JavaScript, Fourth Edition
 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.
1 do-while Statement 2 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX.
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
Conditional Control Structures Chapter 5. Goals and Objectives Understand conditional control structures. Demonstrate the use of decision structures to.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 5 Control Structures II: Repetition.
JavaScript, Sixth Edition
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.
Conditional Control Structures Chapter 5 Review. The If Statement The if statement is a conditional control structure, also called a decision structure,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
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 5 The if Statement
Chapter 6: Loops.
Chapter 15 - JavaScript/JScript: Control Structures II
CiS 260: App Dev I Chapter 4: Control Structures II.
Chapter 19 JavaScript.
JavaScript: Control Statements (II)
Chapter 4 Conditionals.
Chapter 9 - JavaScript: Control Structures II
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 4 - Program Control
Chapter 8: More on the Repetition Structure
Lab5 PROGRAMMING 1 Loop chapter4.
Program Flow.
Chapter 4 - Program Control
Another Example Problem
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

Chapter 9: Control Statements II CIS 275—Web Application Development for Business I

2 LoopingLooping I ______ loop for (i = 0; i <= 5; i++) { document.write("The number is " + i + “ ”); } ________ loop i = 0 while (i <= 5) { document.write("The number is " + i + “ ”); i++; }

3 Looping II __________ loop do { document.write("The number is " + i); document.write(" "); i++; } while (i <= 5)

4 Math Object Rounding a number Rounding Math.round(7.25) returns _____ Generate a random number between 0 and 1random number Math.random() Generate an integer between 0 and 9 randomlyinteger Math.floor(Math.random()*10) Find the minimum of a series of numbersminimum Math.min(2, 4, 6, 7, 1) returns _____ Find the square root of a number Math.sqrt(49) returns ____ Raise a number to a power Math.pow(2, 8) returns _____

5 ConditionalConditional II _________ statement var d = new Date(); var theDay=d.getDay(); switch (theDay) { case 5: document.write("Finally Friday"); break; case 6: document.write("Super Saturday"); break; case 0: document.write("Sleepy Sunday"); break; default: document.write("I'm really looking forward to this+ weekend!"); }

6 break Statement break is used to exit early from the immediately enclosing structure. for(var count = 1; count <= 10; ++count){ if(count == 5) break; document.write(“Count is: ” + count + “ ”); } Labeled break causes exit from the labeled block stop: { // imagine a series of nested control structures if(i == 5) break stop; // end of nested control structures } // end of labeled block

7 continue Statement continue skips to the next iteration of the immediately enclosing structure. for(var count = 1; count <= 10; ++count){ if(count == 5) continue; document.write(“Count is: ” + count + “ ”); } Labeled continue skips to the next iteration of the labeled structure. nextRow: // imagine several nested control structures continue nextRow; // end of nested control structures }

8 Logical Operators and Expressions Logical (or Boolean) operators in JavaScript ! expression ! means ______ true becomes false, false becomes true expression1 && expression2 && means ______ both expressions must be true for the whole to be true expression1 || expression2 || means ______ both expressions must be false for the whole to be false Examples (5 ‘B’) is _______ !(5 ‘B’) is _______

9 Structured Programming Rules Only single-entry/single-exit control structures are used. Control structure _________: The exit point of one control structure is connected to the entry point of the next control structure. To create a structured program 1. Start with the “simplest flowchart” 2. Any rectangle can be replaced by two rectangles in sequence 3. Any rectangle can be replaced by any control structure 4. Rules 2 and 3 may be applied as often as desired and in any order