 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 17 - WMLScript: Control Structures I Outline 17.1 Introduction 17.2 Algorithms 17.3 Pseudocode.

Slides:



Advertisements
Similar presentations
Types of selection structures
Advertisements

 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
 2002 Prentice Hall. All rights reserved Control Structures 3 control structures –Sequential structure Built into Python –Selection structure The.
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
Chapter 3 - Structured Program Development
 2001 Deitel & Associates, Inc. All rights reserved. 1 Outline 14.1Introduction 14.2Algorithms 14.3Pseudocode 14.4Control Structures 14.5The if Selection.
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4: Control Structures: Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection Statement 4.6 if else Selection Statement 4.7 while.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Structured Program Development in C
 2002 Prentice Hall. All rights reserved. 1 Chapter 3 – Control Structures Outline 3.1 Introduction 3.2 Algorithms 3.3 Pseudocode 3.4Control Structures.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
The University of Texas – Pan American
 2003 Prentice Hall, Inc. All rights reserved.  2004 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1.
1 CSCE 1030 Computer Science 1 Control Statements in Java.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4: Control Structures: Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
4.1 Introduction Structured programming –Control structures Helpful in building and manipulating objects BZUPAGES.COM.
C Lecture Notes 1 Structured Program Development.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
C++ Programming Lecture 6 Control Structure II (Repetition) By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Control Structures: Part 1.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Control Structures: Part 1 Outline 4.1Introduction 4.2Algorithms 4.3Pseudocode 4.4Control.
 2003 Prentice Hall, Inc. All rights reserved. 1 Control Structures Outline -Introduction -Algorithms -Pseudocode -Control Structures -if Selection Structure.
C Programming 2002 Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection.
 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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
1 JavaScript: Control Structures. 2 Control Structures Flowcharting JavaScript’s sequence structure.
1 Lecture 3 Control Structures else/if and while.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
Introduction to Computers and Programming Lecture 7:
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline Counter-Controlled Repetition: Example Sentinel-Controlled Repetition:
CSCI/CMPE 4341 Topic: Programming in Python Chapter 4: Control Structures (Part 2) Xiang Lian The University of Texas – Pan American Edinburg, TX
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
1 JavaScript/Jscript 2 Control Structures I. 2 Introduction Before programming a script have a –Thorough understanding of problem –Carefully planned approach.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
Chapter 14 - JavaScript/JScript: Control Structures I
JavaScript: Control Structures I
Algorithm: procedure in terms of
while Repetition Structure
Chapter 8 - JavaScript: Control Statements I
Chapter 4 – Control Structures Part 1
Chapter 8 - JavaScript: Control Structures I
Structured Program
Chapter 3 - Structured Program Development
Chapter 3 – Control Structures
Chapter 3 - Structured Program Development
Chapter 4 - Control Structures: Part 1
EPSII 59:006 Spring 2004.
Chapter 8 - JavaScript: Control Structures I
Presentation transcript:

 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 17 - WMLScript: Control Structures I Outline 17.1 Introduction 17.2 Algorithms 17.3 Pseudocode 17.4 Control Structures 17.5 if Selection Structure 17.6 if/else Selection Structure 17.7 while Repetition Structure 17.8 Formulating Algorithms: Case Study 1 (Counter- Controlled Repetition) 17.9 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) Assignment Operators Increment and Decrement Operators Note on Data Types WMLScript Internet and World Wide Web Resources

 2001 Prentice Hall, Inc. All rights reserved Control Structures Fig. 17.1Flowcharting WMLScript’s sequence structure.

 2001 Prentice Hall, Inc. All rights reserved if Selection Structure Fig. 17.2Flowcharting the single-selection if structure.

 2001 Prentice Hall, Inc. All rights reserved if/else Selection Structure Fig. 17.3Flowcharting the double-selection if/else structure. “Passed”

 2001 Prentice Hall, Inc. All rights reserved while Repetition Structure Fig. 17.4Flowcharting the while repetition structure.

 2001 Prentice Hall, Inc. All rights reserved. Outline 6 1 // Fig. 17.6: mean1.wmls 2 // Class average program 3 4 extern function average() 5 { 6 var total = 0; // clear total 7 var gradeCounter = 1; // prepare to loop 8 var grade; // grade input 9 var gradeValue; // number returned by parseInt method while ( gradeCounter <= 10 ){ // loop 10 times 12 grade = Dialogs.prompt( "Enter integer grade", "" ); gradeValue = Lang.parseInt( grade ); total += gradeValue; gradeCounter; 19 } var average = String.format( "%3.2f", ( total / 10 ) ); WMLBrowser.setVar( "classAve", average ); 24 WMLBrowser.go( "#classAverage" ); 25 } Mean1.wmls Loop 10 times. Prompt for user input. Convert the user input to an integer. Add the value input by the user to the total.Increment the counter. Calculate the average.

 2001 Prentice Hall, Inc. All rights reserved. Outline Click Enter to enter the grades The class average is: $classAve Fig17_7.wml Display the class average.

 2001 Prentice Hall, Inc. All rights reserved. Outline 8

 2001 Prentice Hall, Inc. All rights reserved. Outline 9

 2001 Prentice Hall, Inc. All rights reserved. Outline 10 1 // Fig. 17.9: mean2.wmls 2 // Class average program 3 4 extern function average2() 5 { 6 var total = 0; // clear total 7 var gradeCounter = 0; // prepare to loop 8 var average; 9 10 // prompt for input and read grade from user 11 var grade = Dialogs.prompt( "Enter integer grade," + 12 "(-1) to Quit", "" ); // convert grade from a string to an integer 15 var gradeValue = Lang.parseInt( grade ); while ( gradeValue != (-1) ) { // add gradeValue to total 20 total = total + gradeValue; // increment gradeCounter 23 ++gradeCounter; // prompt for input and read grade from user 26 grade = Dialogs.prompt( "Enter integer grade, " + 27 "(-1) to Quit", "" ); // convert grade from string to integer 30 gradeValue = Lang.parseInt( grade ); 31 } 32 Mean2.wmls Prompt for user input.Convert user input to an integer. Loop until a value of –1 is entered by user. Add grade entered to total.Prompt for user input.

 2001 Prentice Hall, Inc. All rights reserved. Outline // termination phase 34 if ( gradeCounter != 0 ) { 35 average = 36 String.format( "%3.2f", ( total / gradeCounter ) ); 37 } 38 else { 39 average = "No grades were entered"; 40 } WMLBrowser.setVar( "classAve", average ); 43 WMLBrowser.go( "#classAverage" ); 44 } Mean2.wmls Calculate class average.Display an error message if no grades were entered.

 2001 Prentice Hall, Inc. All rights reserved. Outline Click Enter to enter the grades The class average is: $classAve Fig17_10.wml Display the class average.

 2001 Prentice Hall, Inc. All rights reserved. Outline 13

 2001 Prentice Hall, Inc. All rights reserved. Outline 14 1 // Fig : count.wmls 2 // Examination-results program 3 4 extern function passFail() 5 { 6 var passes = 0; // number of passes 7 var failures = 0; // number of failures 8 var student = 1; // student counter 9 10 while ( student 8 ) { 27 WMLBrowser.setVar( "tooMany", "Raise Tuition" ); 28 } WMLBrowser.setVar( "numberPass", passes ); 31 WMLBrowser.setVar( "numberFail", failures ); 32 WMLBrowser.go( "#results" ); 33 } count.wmls Loop 10 times.Prompt for user input. Update value of passes if a 1 was entered.Update the value of failures if anything accept a 1 was entered. Update the counter.

 2001 Prentice Hall, Inc. All rights reserved. Outline Click Run to run script Examination results: 27 Passed: $numberPass 28 Failed: $numberFail 29 $tooMany Fig17_13.wml Display the results.

 2001 Prentice Hall, Inc. All rights reserved. Outline 16

 2001 Prentice Hall, Inc. All rights reserved. Outline 17

 2001 Prentice Hall, Inc. All rights reserved Increment and Decrement Operators

 2001 Prentice Hall, Inc. All rights reserved Increment and Decrement Operators

 2001 Prentice Hall, Inc. All rights reserved. Outline 20 1 // Fig : incrementScript.wmls 2 // Increment example 3 4 extern function increment() 5 { 6 var variable1 = 5; // initial variable 7 var variable2 = 5; // initial variable 8 var post1, post2, post3; // results of increment 9 var pre1, pre2, pre3; // results of decrement post1 = variable1; 13 post2 = variable1++; // increment 14 post3 = variable1; pre1 = variable2; 17 pre2 = ++variable2; // decrement 18 pre3 = variable2; WMLBrowser.setVar( "postResult", post1 ); 21 WMLBrowser.setVar( "postResult2", post2 ); 22 WMLBrowser.setVar( "postResult3", post3 ); 23 WMLBrowser.setVar( "preResult", pre1 ); 24 WMLBrowser.setVar( "preResult2", pre2 ); 25 WMLBrowser.setVar( "preResult3", pre3 ); 26 WMLBrowser.refresh(); 27 } IncrementScript.wm ls To begin, the value of variable1 is 5.To begin, the value of variable2 is 5.Postincrement variable1. Preincrement variable2.

 2001 Prentice Hall, Inc. All rights reserved. Outline Postincrementing: 21 $postResult $postResult2 $postResult3 22 Preincrementing: 23 $preResult $preResult2 $preResult Fig17_17.wml Display the results.

 2001 Prentice Hall, Inc. All rights reserved. Outline 22

 2001 Prentice Hall, Inc. All rights reserved Increment and Decrement Operators