Chapter 10 JavaScript/JScript: Control Structures II 289
|
|
- Benjamin Caldwell
- 5 years ago
- Views:
Transcription
1 IW3HTP_10.fm Page 289 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II JavaScript/JScript: Control Structures II 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig. 10.1: WhileCounter.html --> 4 5 <HEAD> 6 <TITLE>Counter-Controlled Repetition</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 var counter = 1; // initialization while ( counter <= 7 ) { // repetition condition 12 document.writeln( "<P><FONT SIZE = '" + counter + 13 "'>HTML font size " + counter + "</FONT></P>" ); 14 ++counter; // increment 15 } 16 </SCRIPT> </HEAD><BODY></BODY> 19 </HTML> Fig Counter-controlled repetition.
2 IW3HTP_10.fm Page 290 Thursday, April 13, :32 PM 290 JavaScript/JScript: Control Structures II Chapter 10 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig. 10.2: ForCounter.html --> 4 5 <HEAD> 6 <TITLE>Counter-Controlled Repetition</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 // Initialization, repetition condition and incrementing 10 // are all included in the for structure header. 11 for ( var counter = 1; counter <= 7; ++counter ) 12 document.writeln( "<P><FONT SIZE = '" + counter + 13 "'>HTML font size " + counter + "</FONT></P>" ); 14 </SCRIPT> </HEAD><BODY></BODY> 17 </HTML> Fig Counter-controlled repetition with the for structure.
3 IW3HTP_10.fm Page 291 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 291 for 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 Components of a typical for header.
4 IW3HTP_10.fm Page 292 Thursday, April 13, :32 PM 292 JavaScript/JScript: Control Structures II Chapter 10 Establish initial value of control variable var counter = 1 Determine if final value of control variable has been reached counter <= 7 false true document.writeln( "<P><FONT SIZE='" + counter + "'>HTML font size " + counter + "</FONT></P>"); Body of loop (this may be many statements) ++counter Increment the control variable Fig Flowcharting a typical for repetition structure.
5 IW3HTP_10.fm Page 293 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig. 10.5: Sum.html --> 4 5 <HEAD> 6 <TITLE>Sum the Even Integers from 2 to 100</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 var sum = 0; for ( var number = 2; number <= 100; number += 2 ) 12 sum += number; document.writeln( "<BIG>The sum of the even integers " + 15 "from 2 to 100 is " + sum + "</BIG>" ); 16 </SCRIPT> </HEAD><BODY></BODY> 19 </HTML> Fig Summation with for.
6 IW3HTP_10.fm Page 294 Thursday, April 13, :32 PM 294 JavaScript/JScript: Control Structures II Chapter 10 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig. 10.6: interest.html --> 4 5 <HEAD> 6 <TITLE>Calculating Compound Interest</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 var amount, principal = , rate =.05; document.writeln( "<TABLE BORDER = '1' WIDTH = '100%'>" ); 12 document.writeln( "<TR><TD WIDTH = '100'><B>Year</B></TD>" ); 13 document.writeln( 14 "<TD><B>Amount on deposit</b></td></tr>" ); for ( var year = 1; year <= 10; ++year ) { 17 amount = principal * Math.pow( rate, year ); 18 document.writeln( "<TR><TD>" + year + "</TD><TD>" + 19 Math.round( amount * 100 ) / "</TD></TR>" ); 20 } document.writeln( "</TABLE>" ); 23 </SCRIPT> </HEAD><BODY></BODY> 26 </HTML> Fig Calculating compound interest with for.
7 IW3HTP_10.fm Page 295 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig. 10.7: SwitchTest.html --> 4 5 <HEAD> 6 <TITLE>Switching between HTML List Formats</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 var choice, // user s choice 10 starttag, // starting list item tag 11 endtag, // ending list item tag 12 validinput = true, // indicates if input is valid 13 listtype; // list type as a string choice = window.prompt( "Select a list style:\n" + 16 "1 (bullet), 2 (numbered), 3 (lettered)", "1" ); switch ( choice ) { 19 case "1": 20 starttag = "<UL>"; 21 endtag = "</UL>"; 22 listtype = "<H1>Bullet List</H1>" 23 break; 24 case "2": 25 starttag = "<OL>"; 26 endtag = "</OL>"; 27 listtype = "<H1>Ordered List: Numbered</H1>" 28 break; 29 case "3": 30 starttag = "<OL TYPE = 'A'>"; 31 endtag = "</OL>"; 32 listtype = "<H1>Ordered List: Lettered</H1>" 33 break; 34 default: 35 validinput = false; 36 } if ( validinput == true ) { 39 document.writeln( listtype + starttag ); for ( var i = 1; i <= 3; ++i ) 42 document.writeln( "<LI>List item " + i + "</LI>" ); document.writeln( endtag ); 45 } 46 else 47 document.writeln( "Invalid choice: " + choice ); 48 </SCRIPT> </HEAD> 51 <BODY> 52 <P>Click Refresh (or Reload) to run the script again</p> 53 </BODY> Fig An example using switch (part 1 of 3).
8 IW3HTP_10.fm Page 296 Thursday, April 13, :32 PM 296 JavaScript/JScript: Control Structures II Chapter </HTML> Fig An example using switch (part 2 of 3).
9 IW3HTP_10.fm Page 297 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 297 Fig An example using switch (part 3 of 3).
10 IW3HTP_10.fm Page 298 Thursday, April 13, :32 PM 298 JavaScript/JScript: Control Structures II Chapter 10 case a true 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) Fig The switch multiple-selection structure.
11 IW3HTP_10.fm Page 299 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig. 10.9: DoWhileTest.html --> 4 5 <HEAD> 6 <TITLE>Using the do/while Repetition Structure</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 var counter = 1; do { 12 document.writeln( "<H" + counter + ">This is an H" + 13 counter + " level head" + "</H" + counter + ">" ); counter; 16 } while ( counter <= 6 ); 17 </SCRIPT> </HEAD><BODY></BODY> 20 </HTML> Fig Using the do/while repetition structure.
12 IW3HTP_10.fm Page 300 Thursday, April 13, :32 PM 300 JavaScript/JScript: Control Structures II Chapter 10 action(s) condition true false Fig Flowcharting the do/while repetition structure.
13 IW3HTP_10.fm Page 301 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig : BreakTest.html --> 4 5 <HEAD> 6 <TITLE>Using the break Statement in a for Structure</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 for ( var count = 1; count <= 10; ++count ) { 10 if ( count == 5 ) 11 break; // break loop only if count == document.writeln( "Count is: " + count + "<BR>" ); 14 } document.writeln( "Broke out of loop at count = " + count ); 17 </SCRIPT> </HEAD><BODY></BODY> 20 </HTML> Fig Using the break statement in a for structure.
14 IW3HTP_10.fm Page 302 Thursday, April 13, :32 PM 302 JavaScript/JScript: Control Structures II Chapter 10 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig : ContinueTest.html --> 4 5 <HEAD> 6 <TITLE>Using the break Statement in a for Structure</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 for ( var count = 1; count <= 10; ++count ) { 10 if ( count == 5 ) 11 continue; // skip remaining code in loop 12 // only if count == document.writeln( "Count is: " + count + "<BR>" ); 15 } document.writeln( "Used continue to skip printing 5" ); 18 </SCRIPT> </HEAD><BODY></BODY> 21 </HTML> Fig Using the continue statement in a for structure.
15 IW3HTP_10.fm Page 303 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig : BreakLabelTest.html --> 4 5 <HEAD> 6 <TITLE>Using the break Statement with a Label</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 stop: { // labeled compound statement 10 for ( var row = 1; row <= 10; ++row ) { 11 for ( var column = 1; column <= 5 ; ++column ) { if ( row == 5 ) 14 break stop; // jump to end of stop block document.write( "* " ); 17 } document.writeln( "<BR>" ); 20 } // the following line is skipped 23 document.writeln( "This line should not print" ); 24 } document.writeln( "End of script" ); 27 </SCRIPT> </HEAD><BODY></BODY> 30 </HTML> Fig Using a labeled break statement in a nested for structure.
16 IW3HTP_10.fm Page 304 Thursday, April 13, :32 PM 304 JavaScript/JScript: Control Structures II Chapter 10 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig : ContinueLabelTest.html --> 4 5 <HEAD> 6 <TITLE>Using the continue Statement with a Label</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 nextrow: // target label of continue statement 10 for ( var row = 1; row <= 5; ++row ) { 11 document.writeln( "<BR>" ); for ( var column = 1; column <= 10; ++column ) { if ( column > row ) 16 continue nextrow; // next iteration of 17 // labeled loop document.write( "* " ); 20 } 21 } 22 </SCRIPT> </HEAD><BODY></BODY> 25 </HTML> Fig Using a labeled continue statement in a nested for structure.
17 IW3HTP_10.fm Page 305 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 305 expression1 expression2 expression1 && expression2 false false false false true false true false false true true true Fig Truth table for the && (logical AND) operator.
18 \ IW3HTP_10.fm Page 306 Thursday, April 13, :32 PM 306 JavaScript/JScript: Control Structures II Chapter 10 expression1 expression2 expression1 expression2 false false false false true true true false true true true true Fig Truth table for the (logical OR) operator.
19 IW3HTP_10.fm Page 307 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 307 expression!expression false true true false Fig Truth table for operator! (logical negation).
20 IW3HTP_10.fm Page 308 Thursday, April 13, :32 PM 308 JavaScript/JScript: Control Structures II Chapter 10 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <HTML> 3 <!-- Fig : LogicalOperators.html --> 4 5 <HEAD> 6 <TITLE>Demonstrating the Logical Operators</TITLE> 7 8 <SCRIPT LANGUAGE = "JavaScript"> 9 document.writeln( "<TABLE BORDER = '1' WIDTH = '100%'>" ); document.writeln( 12 "<TR><TD WIDTH = '25%'>Logical AND (&&)</TD>" + 13 "<TD>false && false: " + ( false && false ) + 14 "<BR>false && true: " + ( false && true ) + 15 "<BR>true && false: " + ( true && false ) + 16 "<BR>true && true: " + ( true && true ) + "</TD>" ); document.writeln( 19 "<TR><TD WIDTH = '25%'>Logical OR ( )</TD>" + 20 "<TD>false false: " + ( false false ) + 21 "<BR>false true: " + ( false true ) + 22 "<BR>true false: " + ( true false ) + 23 "<BR>true true: " + ( true true ) + "</TD>" ); document.writeln( 26 "<TR><TD WIDTH = '25%'>Logical NOT (!)</TD>" + 27 "<TD>!false: " + (!false ) + 28 "<BR>!true: " + (!true ) + "</TD>" ); document.writeln( "</TABLE>" ); 31 </SCRIPT> </HEAD><BODY></BODY> 34 </HTML> Fig Demonstrating the logical operators (part 1 of 2).
21 IW3HTP_10.fm Page 309 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 309 Fig Demonstrating the logical operators (part 2 of 2).
22 IW3HTP_10.fm Page 310 Thursday, April 13, :32 PM 310 JavaScript/JScript: Control Structures II Chapter 10 Operators Associativity Type () left to right parentheses ++ --! right to left unary * / % left to right multiplicative + - left to right additive < <= > >= left to right relational ==!= left to right equality && left to right logical AND left to right logical OR?: right to left conditional = += -= *= /= %= right to left assignment Fig Precedence and associativity of the operators discussed so far.
23 IW3HTP_10.fm Page 311 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 311 Sequence Selection Repetition while structure if/else structure (double selection) if structure (single selection) T T F T F F do/while structure switch structure (multiple selection) break T T F break T F for structure F... T break T F F Fig JavaScript s single-entry/single-exit sequence, selection and repetition structures.
24 IW3HTP_10.fm Page 312 Thursday, April 13, :32 PM 312 JavaScript/JScript: Control Structures II Chapter 10 Rules for Forming Structured Programs 1) Begin with the simplest flowchart (Fig ). 2) Any rectangle (action) can be replaced by two rectangles (actions) in sequence. 3) Any rectangle (action) can be replaced by any control structure (sequence, if, if/else, switch, while, do/while or for). 4) Rules 2 and 3 may be applied as often as you like and in any order. Fig Rules for forming structured programs.
25 IW3HTP_10.fm Page 313 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 313 Fig The simplest flowchart.
26 IW3HTP_10.fm Page 314 Thursday, April 13, :32 PM 314 JavaScript/JScript: Control Structures II Chapter 10 Rule 2 Rule 2 Rule 2... Fig Repeatedly applying rule 2 of Fig to the simplest flowchart.
27 IW3HTP_10.fm Page 315 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 315 Rule 3 Rule 3 Rule 3 Fig Applying rule 3 of Fig to the simplest flowchart.
28 IW3HTP_10.fm Page 316 Thursday, April 13, :32 PM 316 JavaScript/JScript: Control Structures II Chapter 10 Stacked building blocks Nested building blocks Overlapping building blocks (Illegal in structured programs) Fig Stacked, nested and overlapped building blocks.
29 IW3HTP_10.fm Page 317 Thursday, April 13, :32 PM Chapter 10 JavaScript/JScript: Control Structures II 317 Fig An unstructured flowchart.
Chapter 9 - JavaScript: Control Structures II
Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled Repetition 9.3 for Repetition Structure 9. Examples Using the for Structure 9.5 switch Multiple-Selection
More informationJavascript Lesson 3: Controlled Structures ANDREY KUTASH
Javascript Lesson 3: Controlled Structures ANDREY KUTASH 10.1 Introduction Before programming a script have a Thorough understanding of problem Carefully planned approach to solve it When writing a script,
More informationChapter 8 JavaScript/JScript: Introduction to Scripting 201
iw3htp_08.fm Page 201 Thursday, April 13, 2000 12:30 PM Chapter 8 JavaScript/JScript: Introduction to Scripting 201 8 JavaScript/JScript: Introduction to Scripting 1
More information334 JavaScript/JScript: Functions Chapter 11. boss. worker1 worker2 worker3. Hierarchical boss function/worker function relationship.
. iw3htp_11.fm Page 334 Thursday, April 13, 2000 12:33 PM 334 JavaScript/JScript: Functions Chapter 11 11 JavaScript/JScript: Functions boss worker1 worker2 worker3 worker4 worker5 Fig. 11.1 Hierarchical
More informationChapter 4 C Program Control
1 Chapter 4 C Program Control Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 4 C Program Control Outline 4.1 Introduction 4.2 The Essentials of Repetition
More informationJavaScript: Control Statements I Pearson Education, Inc. All rights reserved.
1 7 JavaScript: Control Statements I 2 Let s all move one place on. Lewis Carroll The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert
More informationLoops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017
Loops! Loops! Loops! Lecture 5 COP 3014 Fall 2017 September 25, 2017 Repetition Statements Repetition statements are called loops, and are used to repeat the same code mulitple times in succession. The
More informationLECTURE 5 Control Structures Part 2
LECTURE 5 Control Structures Part 2 REPETITION STATEMENTS Repetition statements are called loops, and are used to repeat the same code multiple times in succession. The number of repetitions is based on
More informationChapter 4 C Program Control
Chapter C Program Control 1 Introduction 2 he Essentials of Repetition 3 Counter-Controlled Repetition he for Repetition Statement 5 he for Statement: Notes and Observations 6 Examples Using the for Statement
More information2.11 Assignment Operators. Assignment expression abbreviations c = c + 3; can be abbreviated as c += 3; using the addition assignment operator
2.11 Assignment Operators 1 Assignment expression abbreviations c = c + 3; can be abbreviated as c += 3; using the addition assignment operator Statements of the form variable = variable operator expression;
More informationChapter 11 - JavaScript: Arrays
Chapter - JavaScript: Arrays 1 Outline.1 Introduction.2 Arrays.3 Declaring and Allocating Arrays. Examples Using Arrays.5 References and Reference Parameters.6 Passing Arrays to Functions. Sorting Arrays.8
More informationC Program Control. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan
C Program Control Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline The for repetition statement switch multiple selection statement break
More informationChapter 5 Control Structures: Part 2
Chapter 5 Control Structures: Part 2 Essentials of Counter-Controlled Repetition Counter-controlled repetition requires: Name of control variable (loop counter) Initial value of control variable Increment/decrement
More informationJAVASCRIPT LESSON 4: FUNCTIONS
JAVASCRIPT LESSON 4: FUNCTIONS 11.1 Introductio n Programs that solve realworld programs More complex than programs from previous chapters Best way to develop & maintain large program: Construct from small,
More informationTheory of control structures
Theory of control structures Paper written by Bohm and Jacopini in 1966 proposed that all programs can be written using 3 types of control structures. Theory of control structures sequential structures
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers
More informationJavaScript: Introduction to Scripting
iw3htp2.book Page 194 Wednesday, July 18, 2001 9:01 AM 7 JavaScript: Introduction to Scripting Objectives To be able to write simple JavaScript programs. To be able to use input and output statements.
More informationJavaScript: Control Statements I
7 JavaScript: Control Statements I OBJECTIVES In this chapter you will learn: Basic problem-solving techniques. To develop algorithms through the process of top-down, stepwise refinement. To use the if
More informationLecture 6 Part a: JavaScript
Lecture 6 Part a: JavaScript G64HLL, High Level Languages http://www.cs.nott.ac.uk/~gxo/g64hll.html Dr. Gabriela Ochoa gxo@cs.nott.ac.uk Previous lecture Basics of java script The document, window objects
More informationM275 - Web Development using PHP and MySQL
Arab Open University Faculty of computer Studies M275 - Web Development using PHP and MySQL Chapter 6 Flow Control Functions in PHP Summary This is a supporting material to chapter 6. This summary will
More informationFlow of Control. Relational Operators. Operators Review. Order of Operations
Flow of Control Definition: The sequential execution of statements in a program Sequential Control Structure (Top-Bottom) It is characterized by a flow chart construct without branches. Selection Control
More informationChapter 7: Javascript: Control Statements. Background and Terminology. Background and Terminology. Background and Terminology
Chapter 7: Javascript: Control Statements CS 80: Internet Programming Instructor: Mark Edmonds Background and Terminology Algorithm What is an algorithm? A procedure for solving a problem. Consists of:
More informationStructured Program Development in C
1 3 Structured Program Development in C 3.2 Algorithms 2 Computing problems All can be solved by executing a series of actions in a specific order Algorithm: procedure in terms of Actions to be executed
More informationFundamentals of Programming Session 9
Fundamentals of Programming Session 9 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationThe first sample. What is JavaScript?
Java Script Introduction JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari. In this lecture
More informationProgramming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029
Programming Basics and Practice GEDB029 Decision Making, Branching and Looping Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Decision Making and Branching C language possesses such decision-making capabilities
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical
More informationBIL101E: Introduction to Computers and Information systems Lecture 8
BIL101E: Introduction to Computers and Information systems Lecture 8 8.1 Algorithms 8.2 Pseudocode 8.3 Control Structures 8.4 Decision Making: Equality and Relational Operators 8.5 The if Selection Structure
More informationIntroduction. C provides two styles of flow control:
Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if
More informationChapter 2: Functions and Control Structures
Chapter 2: Functions and Control Structures TRUE/FALSE 1. A function definition contains the lines of code that make up a function. T PTS: 1 REF: 75 2. Functions are placed within parentheses that follow
More informationProgram Design Phase. Algorithm Design - Mathematical. Algorithm Design - Sequence. Verify Algorithm Y = MX + B
Program Design Phase Write Program Specifications Analysis of requirements Program specifications description Describe what the goals of the program Describe appearance of input and output Algorithm Design
More informationChapter 2 - Control Structures
Chapter 2 - Control Structures 1 2.11 Assignment Operators 2.12 Increment and Decrement Operators 2.13 Essentials of Counter-Controlled Repetition 2.1 for Repetition Structure 2.15 Examples Using the for
More informationChapter 4 Control Structures: Part 2
Chapter 4 Control Structures: Part 2 1 2 Essentia ls of Counter-Controlled Repetition Counter-controlled repetition requires: Control variable (loop counter) Initial value of the control variable Increment/decrement
More informationWorking with JavaScript
Working with JavaScript Creating a Programmable Web Page for North Pole Novelties 1 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page 2 Objectives
More informationNotesc120Mar515.notebook. March 05, Next I want to change the logic to handle all four of these:
Next I want to change the logic to handle all four of these: Note after the else I have two curly braces and embedded inside them I ask the next question and deal with its yes and its no. 1 Flowchart of
More informationComputational Expression
Computational Expression Conditionals Janyl Jumadinova 10 October, 2018 Janyl Jumadinova Computational Expression 10 October, 2018 1 / 16 Computational Thinking: a problem solving process Decomposition
More informationHTML5 and CSS3 More JavaScript Page 1
HTML5 and CSS3 More JavaScript Page 1 1 HTML5 and CSS3 MORE JAVASCRIPT 3 4 6 7 9 The Math Object The Math object lets the programmer perform built-in mathematical tasks Includes several mathematical methods
More informationJavaScript: Introductionto Scripting
6 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask, What would be the most fun? Peggy Walker Equality,
More informationCHAPTER 5: JavaScript Basics 99
CHAPTER 5: JavaScript Basics 99 5.2 JavaScript Keywords, Variables, and Operators 5.2.1 JavaScript Keywords break case continue default delete do else export false for function if import in new null return
More informationThere are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.
Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate
More informationPeople = End Users & Programmers. The Web Browser Application. Program Design Phase. Algorithm Design -Mathematical Y = MX + B
The Web Browser Application People = End Users & Programmers Clients and Components Input from mouse and keyboard Controller HTTP Client FTP Client TCP/IP Network Interface HTML/XHTML CSS JavaScript Flash
More informationControl Statements. Musa M. Ameen Computer Engineering Dept.
2 Control Statements Musa M. Ameen Computer Engineering Dept. 1 OBJECTIVES In this chapter you will learn: To use basic problem-solving techniques. To develop algorithms through the process of topdown,
More information204111: Computer and Programming
204111: Computer and Programming Week 4: Control Structures t Monchai Sopitkamon, Ph.D. Overview Types of control structures Using selection structure Using repetition structure Types of control ol structures
More informationJavaScript: Functions Pearson Education, Inc. All rights reserved.
1 9 JavaScript: Functions 2 Form ever follows function. Louis Sullivan E pluribus unum. (One composed of many.) Virgil O! call back yesterday, bid time return. William Shakespeare Call me Ishmael. Herman
More informationC++ Programming Lecture 7 Control Structure I (Repetition) Part I
C++ Programming Lecture 7 Control Structure I (Repetition) Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department while Repetition Structure I Repetition structure Programmer
More informationWhy Is Repetition Needed?
Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable
More informationChapter 2 - Control Structures
Chapter 2 - Control Structures 1 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure 2.8 Formulating
More informationChapter 1 Introduction to Computers and the Internet
CPET 499/ITC 250 Web Systems Dec. 6, 2012 Review of Courses Chapter 1 Introduction to Computers and the Internet The Internet in Industry & Research o E Commerce & Business o Mobile Computing and SmartPhone
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 5: Control Structures II (Repetition) Why Is Repetition Needed? Repetition allows you to efficiently use variables Can input,
More informationChapter 2 - Control Structures
Chapter 2 - Control Structures 1 Outline 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure
More informationWeek 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.
Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than
More informationInternet publishing HTML (XHTML) language. Petr Zámostný room: A-72a phone.:
Internet publishing HTML (XHTML) language Petr Zámostný room: A-72a phone.: 4222 e-mail: petr.zamostny@vscht.cz Essential HTML components Element element example Start tag Element content End tag
More informationIntroduction to Programming
Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines
More informationCSC Web Programming. Introduction to JavaScript
CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its
More informationClass 9. Choose the correct answer:
Class 9 Choose the correct answer: 1. Which one of the following is a looping statement? a) if b) break c) continue d) for 2. A sequence of instructions that may be repeatedly executed is a) Loop b) if
More informationHTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.
HTML Summary Structure All of the following are containers. Structure Contains the entire web page. Contains information
More informationChapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?
Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct and use countercontrolled, sentinel-controlled,
More informationStructured Program Development
Structured Program Development Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Introduction The selection statement if if.else switch The
More informationC++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures
More informationCS 1124 Media computation. Lab 9.3 October 24, 2008 Steve Harrison
CS 1124 Media computation Lab 9.3 October 24, 2008 Steve Harrison Today using strings to write HTML HTML From text to HTML to XML and beyond... 3 HTML is not a programming language Using HTML is called
More informationChapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?
Chapter 3 - Simple JavaScript - Programming Basics Lesson 1 - JavaScript: What is it and what does it look like? PP presentation JavaScript.ppt. Lab 3.1. Lesson 2 - JavaScript Comments, document.write(),
More informationLoops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz
Loops and Files Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Chapter Topics o The Increment and Decrement Operators o The while Loop o Shorthand Assignment Operators o The do-while
More informationDynamism and Detection
1 Dynamism and Detection c h a p t e r ch01 Page 1 Wednesday, June 23, 1999 2:52 PM IN THIS CHAPTER Project I: Generating Platform-Specific Content Project II: Printing Copyright Information and Last-Modified
More informationControl Structures (Deitel chapter 4,5)
Control Structures (Deitel chapter 4,5) 1 2 Plan Control Structures ifsingle-selection Statement if else Selection Statement while Repetition Statement for Repetition Statement do while Repetition Statement
More informationIntroduction to HTML. SSE 3200 Web-based Services. Michigan Technological University Nilufer Onder
Introduction to HTML SSE 3200 Web-based Services Michigan Technological University Nilufer Onder What is HTML? Acronym for: HyperText Markup Language HyperText refers to text that can initiate jumps to
More information182 Introduction to Microsoft Visual InterDev 6 Chapter 7
iw3htp_07.fm Page 182 Thursday, April 13, 2000 12:29 PM 182 Introduction to Microsoft Visual InterDev 6 Chapter 7 7 Introduction to Microsoft Visual InterDev 6 New tab Other tabs for opening existing projects
More informationComputer Programming: C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #4 Loops Part II Contents Loop Control Statement
More informationintroduction to XHTML
introduction to XHTML XHTML stands for Extensible HyperText Markup Language and is based on HTML 4.0, incorporating XML. Due to this fusion the mark up language will remain compatible with existing browsers
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationC++ PROGRAMMING SKILLS Part 2 Programming Structures
C++ PROGRAMMING SKILLS Part 2 Programming Structures If structure While structure Do While structure Comments, Increment & Decrement operators For statement Break & Continue statements Switch structure
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program Objectives After studying this chapter, you should be able to: Include the selection structure in pseudocode
More informationFlow Control: Branches and loops
Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the
More informationLecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan
Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful
More informationSecond Term ( ) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah
COMPUTER PROGRAMMING SKILLS (4800153-3) CHAPTER 5: REPETITION STRUCTURE Second Term (1437-1438) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah Table of Contents Objectives
More informationIn this chapter you will learn:
1 In this chapter you will learn: Essentials of counter-controlled repetition. Use for, while and do while to execute statements in program repeatedly. Use nested control statements in your program. 2
More informationCHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad Outline 1. C++ Iterative Constructs 2. The for Repetition Structure 3. Examples Using the for Structure 4. The while Repetition Structure
More informationExercise 1: Basic HTML and JavaScript
Exercise 1: Basic HTML and JavaScript Question 1: Table Create HTML markup that produces the table as shown in Figure 1. Figure 1 Question 2: Spacing Spacing can be added using CellSpacing and CellPadding
More informationCOMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)
COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017) RAMANA ISUKAPALLI RAMANA@CS.COLUMBIA.EDU 1 LECTURE-1 Course overview See http://www.cs.columbia.edu/~ramana Overview of HTML Formatting, headings,
More informationControl Statements. Objectives. ELEC 206 Prof. Siripong Potisuk
Control Statements ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program The program
More informationINFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript
INFS 2150 Introduction to Web Development and e-commerce Technology Programming with JavaScript 1 Objectives JavaScript client-side programming Example of a JavaScript program The element
More informationObjectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1
Objectives INFS 2150 Introduction to Web Development and e-commerce Technology Programming with JavaScript JavaScript client-side programming Example of a JavaScript program The element
More informationChapter 3 Structured Program Development
1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction
More informationInternet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e Sequential execution Execute statements in the order they appear in the code Transfer of control Changing the order in which statements execute All scripts
More informationUnit 20 - Client Side Customisation of Web Pages. Week 4 Lesson 5 Fundamentals of Scripting
Unit 20 - Client Side Customisation of Web Pages Week 4 Lesson 5 Fundamentals of Scripting The story so far... three methods of writing CSS: In-line Embedded }These are sometimes called External } block
More informationJAVASCRIPT LOOPS. Date: 13/05/2012 Page: 1 Total Chars: 4973 Total Words: 967
Date: 13/05/2012 Procedure: JavaScript - Loops Source: LINK (http://webcheatsheet.com/javascript/loops.php) Permalink: LINK (http://heelpbook.altervista.org/2012/javascript-loops) Created by: HeelpBook
More informationLecture 7 Tao Wang 1
Lecture 7 Tao Wang 1 Objectives In this chapter, you will learn about: Interactive loop break and continue do-while for loop Common programming errors Scientists, Third Edition 2 while Loops while statement
More informationDECISION CONTROL AND LOOPING STATEMENTS
DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL STATEMENTS Decision control statements are used to alter the flow of a sequence of instructions. These statements help to jump from one part of
More information5. Selection: If and Switch Controls
Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation
More informationTest #2 October 8, 2015
CPSC 1040 Name: Test #2 October 8, 2015 Closed notes, closed laptop, calculators OK. Please use a pencil. 100 points, 5 point bonus. Maximum score 105. Weight of each section in parentheses. If you need
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationControl Structures. Lecture 4 COP 3014 Fall September 18, 2017
Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls
More information1/22/2017. Chapter 2. Functions and Control Structures. Calling Functions. Objectives. Defining Functions (continued) Defining Functions
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition Objectives In this chapter, you will: Study how to use functions to organize your PHP code Learn about variable scope
More informationYOLOP Language Reference Manual
YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language
More informationInformation Science 1
Information Science 1 Fundamental Programming Constructs (1) Week 11 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 10 l Flow of control
More informationINDIAN SCHOOL DARSAIT FIRST TERM EXAM- MAY 2017 MULTIMEDIA AND WEB TECHNOLOGY (067) SAMPLE PAPER Class: XI Max.Marks: 70
INDIAN SCHOOL DARSAIT FIRST TERM EXAM- MAY 07 MULTIMEDIA AND WEB TECHNOLOGY (067) SAMPLE PAPER Class: XI Max.Marks: 70 Date: 6-09-07 Time: 3hr. Answer the following questions based on HTML. a) Differentiate
More informationA Look Back at Arithmetic Operators: the Increment and Decrement
A Look Back at Arithmetic Operators: the Increment and Decrement Spring Semester 2016 Programming and Data Structure 27 Increment (++) and Decrement (--) Both of these are unary operators; they operate
More informationFlow of Control. Flow of control The order in which statements are executed. Transfer of control
1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control
More informationENGR 1181 MATLAB 09: For Loops 2
ENGR 1181 MATLAB 09: For Loops Learning Objectives 1. Use more complex ways of setting the loop index. Construct nested loops in the following situations: a. For use with two dimensional arrays b. For
More information