SlideShare a Scribd company logo
1 of 36
IPA
1st
Semester, 2007-2008
Internet 1
Ch. 9
JavaScript:
Control Statements I
attasr@ipa.edu.sa
09/30/15 © Reem Al-Attas 2
Introduction
Writing a script
 Thorough understanding of problem
 Carefully planned approach
 Understand the types of building blocks that are
available
 Employ proven program-construction principles
09/30/15 © Reem Al-Attas 3
Algorithms
Actions to be executed
Order in which the actions are to be
executed
09/30/15 © Reem Al-Attas 4
Pseudocode
Artificial
Informal
Helps programmers develop algorithms
09/30/15 © Reem Al-Attas 5
Flowchart
 Graphical representation of algorithm or portion
of algorithm
 Flowlines
 Indicate the order the actions of the algorithm execute
 Parallelogram
 Input / Output
 Rectangle symbol
 Process
 Oval symbol
 Start / End
 Diamond symbol
 Indicates a decision is to be made
 Small circle symbol
 A portion of algorithm
09/30/15 © Reem Al-Attas 6
Flowchart
add grade to total total = total + grade;
add 1 to counter counter = counter + 1;
09/30/15 © Reem Al-Attas 7
Control Structures
 Sequential execution
 Statements execute in the order they are written
 Transfer of control
 Next statement to execute may not be the next one in sequence
 Three control structures
 Sequence structure
 Selection structure
 if
 if…else
 switch
 Repetition structure
 while
 do…while
 for
 for…in
09/30/15 © Reem Al-Attas 8
if Selection Statement
Indicate action only when the condition
evaluates to true
09/30/15 © Reem Al-Attas 9
if Selection Statement
grade >= 60
true
false
print “Passed”
Fig. 8.3 Flowcharting the single-selection if statement.
09/30/15 © Reem Al-Attas 10
if…else Selection Statement
Indicate different actions to be perform
when condition is true or false
Conditional operator (?:)
 JavaScript’s only ternary operator
 Three operands
 Forms a conditional expression
09/30/15 © Reem Al-Attas 11
if…else Selection Statement
grade >= 60 true
print “Failed”
false
print “Passed”
Fig. 8.4 Flowcharting the double-selection if…else statement.
09/30/15 © Reem Al-Attas 12
while Repetition Statement
Repetition structure (loop)
 Repeat action while some condition remains
true
09/30/15 © Reem Al-Attas 13
while Repetition Statement
product <= 1000 product = 2 * product
true
false
Fig. 8.5 Flowcharting the while repetition statement.
09/30/15 © Reem Al-Attas 14
Formulating Algorithms:
Case Study 1 (Counter-
Controlled Repetition)
Counter-controlled repetition
 Counter
 Control the number of times a set of statements
executes
 Definite repetition
average.html
(1 of 3)
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <!-- Fig. 8.7: average.html -->
6 <!-- Class Average Program -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Class Average Program</title>
11
12 <script type = "text/javascript">
13 <!--
14 var total, // sum of grades
15 gradeCounter, // number of grades entered
16 gradeValue, // grade value
17 average, // average of all grades
18 grade; // grade typed by user
19
20 // Initialization Phase
21 total = 0; // clear total
22 gradeCounter = 1; // prepare to loop
23
average.html
(2 of 3)
24 // Processing Phase
25 while ( gradeCounter <= 10 ) { // loop 10 times
26
27 // prompt for input and read grade from user
28 grade = window.prompt( "Enter integer grade:", "0" );
29
30 // convert grade from a string to an integer
31 gradeValue = parseInt( grade );
32
33 // add gradeValue to total
34 total = total + gradeValue;
35
36 // add 1 to gradeCounter
37 gradeCounter = gradeCounter + 1;
38 }
39
40 // Termination Phase
41 average = total / 10; // calculate the average
42
43 // display average of exam grades
44 document.writeln(
45 "<h1>Class average is " + average + "</h1>" );
46 // -->
47 </script>
48
49 </head>
50 <body>
51 <p>Click Refresh (or Reload) to run the script again<p>
52 </body>
53 </html>
09/30/15 © Reem Al-Attas 18
Formulating Algorithms with
Top-Down, Stepwise
Refinement: Case Study 2
(Sentinel-Controlled Repetition)
Indefinite repetition
 Sentinel value
average2.html
(1 of 3)
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <!-- Fig. 8.9: average2.html -->
6 <!-- Sentinel-controlled Repetition -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Class Average Program:
11 Sentinel-controlled Repetition</title>
12
13 <script type = "text/javascript">
14 <!--
15 var gradeCounter, // number of grades entered
16 gradeValue, // grade value
17 total, // sum of grades
18 average, // average of all grades
19 grade; // grade typed by user
20
21 // Initialization phase
22 total = 0; // clear total
23 gradeCounter = 0; // prepare to loop
24
average2.html
(2 of 3)
25 // Processing phase
26 // prompt for input and read grade from user
27 grade = window.prompt(
28 "Enter Integer Grade, -1 to Quit:", "0" );
29
30 // convert grade from a string to an integer
31 gradeValue = parseInt( grade );
32
33 while ( gradeValue != -1 ) {
34 // add gradeValue to total
35 total = total + gradeValue;
36
37 // add 1 to gradeCounter
38 gradeCounter = gradeCounter + 1;
39
40 // prompt for input and read grade from user
41 grade = window.prompt(
42 "Enter Integer Grade, -1 to Quit:", "0" );
43
44 // convert grade from a string to an integer
45 gradeValue = parseInt( grade );
46 }
47
average2.html
(3 of 3)
48 // Termination phase
49 if ( gradeCounter != 0 ) {
50 average = total / gradeCounter;
51
52 // display average of exam grades
53 document.writeln(
54 "<h1>Class average is " + average + "</h1>" );
55 }
56 else
57 document.writeln( "<p>No grades were entered</p>" );
58 // -->
59 </script>
60 </head>
61
62 <body>
63 <p>Click Refresh (or Reload) to run the script again</p>
64 </body>
65 </html>
09/30/15 © Reem Al-Attas 22
09/30/15 © Reem Al-Attas 23
Formulating Algorithms with
Top-Down, Stepwise
Refinement: Case Study 3
(Nested Control Structures)
Consider problem
Make observations
Top-down, stepwise refinement
analysis.html
(1 of 2)
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <!-- Fig. 8.11: analysis.html -->
6 <!-- Analyzing Exam Results -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Analysis of Examination Results</title>
11
12 <script type = "text/javascript">
13 <!--
14 // initializing variables in declarations
15 var passes = 0, // number of passes
16 failures = 0, // number of failures
17 student = 1, // student counter
18 result; // one exam result
19
20 // process 10 students; counter-controlled loop
21 while ( student <= 10 ) {
22 result = window.prompt(
23 "Enter result (1=pass,2=fail)", "0" );
24
analysis.html
(2 of 2)
25 if ( result == "1" )
26 passes = passes + 1;
27 else
28 failures = failures + 1;
29
30 student = student + 1;
31 }
32
33 // termination phase
34 document.writeln( "<h1>Examination Results</h1>" );
35 document.writeln(
36 "Passed: " + passes + "<br />Failed: " + failures );
37
38 if ( passes > 8 )
39 document.writeln( "<br />Raise Tuition" );
40 // -->
41 </script>
42
43 </head>
44 <body>
45 <p>Click Refresh (or Reload) to run the script again</p>
46 </body>
47 </html>
09/30/15 © Reem Al-Attas 26
09/30/15 © Reem Al-Attas 27
09/30/15 © Reem Al-Attas 28
Assignment Operators
Compound assignment operators
 Abbreviate assignment expressions
09/30/15 © Reem Al-Attas 29
Assignment Operators
Assignment
operator
Initial
value of
variable
Sample
expression
Explanation Assigns
+= c = 3 c += 7 c = c +
7
10 to c
-= d = 5 d -= 4 d = d -
4
1 to d
*= e = 4 e *= 5 e = e *
5
20 to e
/= f = 6 f /= 3 f = f /
3
2 to f
%= g = 12 g %= 9 g = g %
9
3 to g
Fig. 8.12 Arithmetic assignment operators.
09/30/15 © Reem Al-Attas 30
Increment and Decrement
Operators
Preincrement or predecrement operator
 Increment or decrement operator placed before
a variable
Postincrement or postdecrement operator
 Increment or decrement operator placed after a
variable
09/30/15 © Reem Al-Attas 31
Increment and Decrement
Operators
Operator Called Sample
expression
Explanation
++ preincrement ++a Increment a by 1, then use the
new value of a in the
expression in which a resides.
++ postincrement a++ Use the current value of a in
the expression in which a
resides, then increment a by 1.
-- predecrement --b Decrement b by 1, then use the
new value of b in the
expression in which b resides.
-- postdecrement b-- Use the current value of b in
the expression in which b
resides, then decrement b by 1.
Fig. 8.13 increment and decrement operators.
increment.html
(1 of 2)
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <!-- Fig. 8.14: increment.html -->
6 <!-- Preincrementing and Postincrementing -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Preincrementing and Postincrementing</title>
11
12 <script type = "text/javascript">
13 <!--
14 var c;
15
16 c = 5;
17 document.writeln( "<h3>Postincrementing</h3>" );
18 document.writeln( c ); // print 5
19 // print 5 then increment
20 document.writeln( "<br />" + c++ );
21 document.writeln( "<br />" + c ); // print 6
22
23 c = 5;
24 document.writeln( "<h3>Preincrementing</h3>" );
25 document.writeln( c ); // print 5
09/30/15 © Reem Al-Attas 33
increment.html
(2 of 2)
26 // increment then print 6
27 document.writeln( "<br />" + ++c );
28 document.writeln( "<br />" + c ); // print 6
29 // -->
30 </script>
31
32 </head><body></body>
33 </html>
09/30/15 © Reem Al-Attas 34
Increment and Decrement
Operators
Operator Associativity Type
++ -- right to left unary
* / % left to right multiplicative
+ - left to right additive
< <= > >= left to right relational
== != left to right equality
?: right to left conditional
= += -= *= /= %= right to left assignment
Fig. 8.15 Precedence and associativity of the operators
discussed so far.
09/30/15 © Reem Al-Attas 35
Note on Data Types
Loosely typed
 Automatically converts between values of
different types
09/30/15 © Reem Al-Attas 36
Assignment 6
 1) Repeat Ex # 7.26
-solved before- using
Loops.
 2) Exercise # 8.13 in
the text book.
Due Date for A# 5&6:
 Monday before your
lecture.

More Related Content

What's hot

JavaScript Control Statements II
JavaScript Control Statements IIJavaScript Control Statements II
JavaScript Control Statements IIReem Alattas
 
javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operatorsMohit Rana
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arraysHassan Dar
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions Reem Alattas
 
New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5Jamshid Hashimi
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...Edureka!
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 

What's hot (20)

JavaScript Control Statements II
JavaScript Control Statements IIJavaScript Control Statements II
JavaScript Control Statements II
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operators
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Js ppt
Js pptJs ppt
Js ppt
 
Loops in java script
Loops in java scriptLoops in java script
Loops in java script
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Css3
Css3Css3
Css3
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Xml schema
Xml schemaXml schema
Xml schema
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
 
New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 

Viewers also liked

Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Aaron Gustafson
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional StatementsMarlon Jamera
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript FunctionsBrian Moschel
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptWriting MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptRoland Bouman
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statementsnobel mujuji
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Functionxxbeta
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS PresentationShawn Calvert
 

Viewers also liked (10)

Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptWriting MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScript
 
Loops in JavaScript
Loops in JavaScriptLoops in JavaScript
Loops in JavaScript
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Java I/O
Java I/OJava I/O
Java I/O
 
Control statements
Control statementsControl statements
Control statements
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Function
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 

Similar to JavaScript Control Statements

control statements of clangauge (ii unit)
control statements of clangauge (ii unit)control statements of clangauge (ii unit)
control statements of clangauge (ii unit)Prashant Sharma
 
Csphtp1 04
Csphtp1 04Csphtp1 04
Csphtp1 04HUST
 
Dynamic HTML Event Model
Dynamic HTML Event ModelDynamic HTML Event Model
Dynamic HTML Event ModelReem Alattas
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++msharshitha03s
 
Distributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation ProjectDistributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation ProjectAssignmentpedia
 
Distributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation ProjectDistributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation ProjectAssignmentpedia
 
Lecture#3 Algorithms and computing
Lecture#3 Algorithms and computingLecture#3 Algorithms and computing
Lecture#3 Algorithms and computingNUST Stuff
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
Verilog Tasks & Functions
Verilog Tasks & FunctionsVerilog Tasks & Functions
Verilog Tasks & Functionsanand hd
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptSuleman Khan
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.pptsanjay
 

Similar to JavaScript Control Statements (20)

control statements of clangauge (ii unit)
control statements of clangauge (ii unit)control statements of clangauge (ii unit)
control statements of clangauge (ii unit)
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
 
Csphtp1 04
Csphtp1 04Csphtp1 04
Csphtp1 04
 
JavaScript
JavaScriptJavaScript
JavaScript
 
03b loops
03b   loops03b   loops
03b loops
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
 
Dynamic HTML Event Model
Dynamic HTML Event ModelDynamic HTML Event Model
Dynamic HTML Event Model
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Distributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation ProjectDistributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation Project
 
Distributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation ProjectDistributed Radar Tracking Simulation Project
Distributed Radar Tracking Simulation Project
 
Lecture#3 Algorithms and computing
Lecture#3 Algorithms and computingLecture#3 Algorithms and computing
Lecture#3 Algorithms and computing
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Verilog Tasks & Functions
Verilog Tasks & FunctionsVerilog Tasks & Functions
Verilog Tasks & Functions
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 

More from Reem Alattas

Rumble Lights Pitch Deck
Rumble Lights Pitch DeckRumble Lights Pitch Deck
Rumble Lights Pitch DeckReem Alattas
 
NASA Datanauts Water Cooler Chat: Autonomous Design of Modular Robots
NASA Datanauts Water Cooler Chat: Autonomous Design of Modular RobotsNASA Datanauts Water Cooler Chat: Autonomous Design of Modular Robots
NASA Datanauts Water Cooler Chat: Autonomous Design of Modular RobotsReem Alattas
 
She looks just like me 2017
She looks just like me 2017She looks just like me 2017
She looks just like me 2017Reem Alattas
 
Nasa Datanauts Water Cooler Chat: Robotics for Space Exploration
Nasa Datanauts Water Cooler Chat: Robotics for Space ExplorationNasa Datanauts Water Cooler Chat: Robotics for Space Exploration
Nasa Datanauts Water Cooler Chat: Robotics for Space ExplorationReem Alattas
 
Nasa Datanauts Water Cooler Chat: Evolutionary Robots for Space Exploration
Nasa Datanauts Water Cooler Chat: Evolutionary Robots for Space ExplorationNasa Datanauts Water Cooler Chat: Evolutionary Robots for Space Exploration
Nasa Datanauts Water Cooler Chat: Evolutionary Robots for Space ExplorationReem Alattas
 
She Looks Just Like Me 2017
She Looks Just Like Me 2017She Looks Just Like Me 2017
She Looks Just Like Me 2017Reem Alattas
 
Evolutionary Algorithms
Evolutionary AlgorithmsEvolutionary Algorithms
Evolutionary AlgorithmsReem Alattas
 
Evolutionary Robotics
Evolutionary RoboticsEvolutionary Robotics
Evolutionary RoboticsReem Alattas
 
Enhancing input on and above the interactive surface
Enhancing input on and above the interactive surfaceEnhancing input on and above the interactive surface
Enhancing input on and above the interactive surfaceReem Alattas
 
Skinput: Appropriating the Body as an Input Surface
Skinput: Appropriating the Body as an Input SurfaceSkinput: Appropriating the Body as an Input Surface
Skinput: Appropriating the Body as an Input SurfaceReem Alattas
 
XML - EXtensible Markup Language
XML - EXtensible Markup LanguageXML - EXtensible Markup Language
XML - EXtensible Markup LanguageReem Alattas
 
DHTML - Dynamic HTML
DHTML - Dynamic HTMLDHTML - Dynamic HTML
DHTML - Dynamic HTMLReem Alattas
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary SearchReem Alattas
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays Reem Alattas
 
Cascading Style Sheet - CSS
Cascading Style Sheet - CSSCascading Style Sheet - CSS
Cascading Style Sheet - CSSReem Alattas
 
HTML tables- rowspan n colspan
HTML tables- rowspan n colspanHTML tables- rowspan n colspan
HTML tables- rowspan n colspanReem Alattas
 

More from Reem Alattas (20)

Rumble Lights Pitch Deck
Rumble Lights Pitch DeckRumble Lights Pitch Deck
Rumble Lights Pitch Deck
 
NASA Datanauts Water Cooler Chat: Autonomous Design of Modular Robots
NASA Datanauts Water Cooler Chat: Autonomous Design of Modular RobotsNASA Datanauts Water Cooler Chat: Autonomous Design of Modular Robots
NASA Datanauts Water Cooler Chat: Autonomous Design of Modular Robots
 
She looks just like me 2017
She looks just like me 2017She looks just like me 2017
She looks just like me 2017
 
Nasa Datanauts Water Cooler Chat: Robotics for Space Exploration
Nasa Datanauts Water Cooler Chat: Robotics for Space ExplorationNasa Datanauts Water Cooler Chat: Robotics for Space Exploration
Nasa Datanauts Water Cooler Chat: Robotics for Space Exploration
 
Nasa Datanauts Water Cooler Chat: Evolutionary Robots for Space Exploration
Nasa Datanauts Water Cooler Chat: Evolutionary Robots for Space ExplorationNasa Datanauts Water Cooler Chat: Evolutionary Robots for Space Exploration
Nasa Datanauts Water Cooler Chat: Evolutionary Robots for Space Exploration
 
She Looks Just Like Me 2017
She Looks Just Like Me 2017She Looks Just Like Me 2017
She Looks Just Like Me 2017
 
Tran helmet pitch
Tran helmet pitchTran helmet pitch
Tran helmet pitch
 
Evolutionary Algorithms
Evolutionary AlgorithmsEvolutionary Algorithms
Evolutionary Algorithms
 
Evolutionary Robotics
Evolutionary RoboticsEvolutionary Robotics
Evolutionary Robotics
 
Create a Need
Create a NeedCreate a Need
Create a Need
 
Enhancing input on and above the interactive surface
Enhancing input on and above the interactive surfaceEnhancing input on and above the interactive surface
Enhancing input on and above the interactive surface
 
Skinput: Appropriating the Body as an Input Surface
Skinput: Appropriating the Body as an Input SurfaceSkinput: Appropriating the Body as an Input Surface
Skinput: Appropriating the Body as an Input Surface
 
XML - EXtensible Markup Language
XML - EXtensible Markup LanguageXML - EXtensible Markup Language
XML - EXtensible Markup Language
 
PHP Scripting
PHP ScriptingPHP Scripting
PHP Scripting
 
DHTML - Dynamic HTML
DHTML - Dynamic HTMLDHTML - Dynamic HTML
DHTML - Dynamic HTML
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
Cascading Style Sheet - CSS
Cascading Style Sheet - CSSCascading Style Sheet - CSS
Cascading Style Sheet - CSS
 
HTML tables- rowspan n colspan
HTML tables- rowspan n colspanHTML tables- rowspan n colspan
HTML tables- rowspan n colspan
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

JavaScript Control Statements

  • 1. IPA 1st Semester, 2007-2008 Internet 1 Ch. 9 JavaScript: Control Statements I attasr@ipa.edu.sa
  • 2. 09/30/15 © Reem Al-Attas 2 Introduction Writing a script  Thorough understanding of problem  Carefully planned approach  Understand the types of building blocks that are available  Employ proven program-construction principles
  • 3. 09/30/15 © Reem Al-Attas 3 Algorithms Actions to be executed Order in which the actions are to be executed
  • 4. 09/30/15 © Reem Al-Attas 4 Pseudocode Artificial Informal Helps programmers develop algorithms
  • 5. 09/30/15 © Reem Al-Attas 5 Flowchart  Graphical representation of algorithm or portion of algorithm  Flowlines  Indicate the order the actions of the algorithm execute  Parallelogram  Input / Output  Rectangle symbol  Process  Oval symbol  Start / End  Diamond symbol  Indicates a decision is to be made  Small circle symbol  A portion of algorithm
  • 6. 09/30/15 © Reem Al-Attas 6 Flowchart add grade to total total = total + grade; add 1 to counter counter = counter + 1;
  • 7. 09/30/15 © Reem Al-Attas 7 Control Structures  Sequential execution  Statements execute in the order they are written  Transfer of control  Next statement to execute may not be the next one in sequence  Three control structures  Sequence structure  Selection structure  if  if…else  switch  Repetition structure  while  do…while  for  for…in
  • 8. 09/30/15 © Reem Al-Attas 8 if Selection Statement Indicate action only when the condition evaluates to true
  • 9. 09/30/15 © Reem Al-Attas 9 if Selection Statement grade >= 60 true false print “Passed” Fig. 8.3 Flowcharting the single-selection if statement.
  • 10. 09/30/15 © Reem Al-Attas 10 if…else Selection Statement Indicate different actions to be perform when condition is true or false Conditional operator (?:)  JavaScript’s only ternary operator  Three operands  Forms a conditional expression
  • 11. 09/30/15 © Reem Al-Attas 11 if…else Selection Statement grade >= 60 true print “Failed” false print “Passed” Fig. 8.4 Flowcharting the double-selection if…else statement.
  • 12. 09/30/15 © Reem Al-Attas 12 while Repetition Statement Repetition structure (loop)  Repeat action while some condition remains true
  • 13. 09/30/15 © Reem Al-Attas 13 while Repetition Statement product <= 1000 product = 2 * product true false Fig. 8.5 Flowcharting the while repetition statement.
  • 14. 09/30/15 © Reem Al-Attas 14 Formulating Algorithms: Case Study 1 (Counter- Controlled Repetition) Counter-controlled repetition  Counter  Control the number of times a set of statements executes  Definite repetition
  • 15. average.html (1 of 3) 1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <!-- Fig. 8.7: average.html --> 6 <!-- Class Average Program --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Class Average Program</title> 11 12 <script type = "text/javascript"> 13 <!-- 14 var total, // sum of grades 15 gradeCounter, // number of grades entered 16 gradeValue, // grade value 17 average, // average of all grades 18 grade; // grade typed by user 19 20 // Initialization Phase 21 total = 0; // clear total 22 gradeCounter = 1; // prepare to loop 23
  • 16. average.html (2 of 3) 24 // Processing Phase 25 while ( gradeCounter <= 10 ) { // loop 10 times 26 27 // prompt for input and read grade from user 28 grade = window.prompt( "Enter integer grade:", "0" ); 29 30 // convert grade from a string to an integer 31 gradeValue = parseInt( grade ); 32 33 // add gradeValue to total 34 total = total + gradeValue; 35 36 // add 1 to gradeCounter 37 gradeCounter = gradeCounter + 1; 38 } 39 40 // Termination Phase 41 average = total / 10; // calculate the average 42 43 // display average of exam grades 44 document.writeln( 45 "<h1>Class average is " + average + "</h1>" ); 46 // --> 47 </script>
  • 17. 48 49 </head> 50 <body> 51 <p>Click Refresh (or Reload) to run the script again<p> 52 </body> 53 </html>
  • 18. 09/30/15 © Reem Al-Attas 18 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) Indefinite repetition  Sentinel value
  • 19. average2.html (1 of 3) 1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <!-- Fig. 8.9: average2.html --> 6 <!-- Sentinel-controlled Repetition --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Class Average Program: 11 Sentinel-controlled Repetition</title> 12 13 <script type = "text/javascript"> 14 <!-- 15 var gradeCounter, // number of grades entered 16 gradeValue, // grade value 17 total, // sum of grades 18 average, // average of all grades 19 grade; // grade typed by user 20 21 // Initialization phase 22 total = 0; // clear total 23 gradeCounter = 0; // prepare to loop 24
  • 20. average2.html (2 of 3) 25 // Processing phase 26 // prompt for input and read grade from user 27 grade = window.prompt( 28 "Enter Integer Grade, -1 to Quit:", "0" ); 29 30 // convert grade from a string to an integer 31 gradeValue = parseInt( grade ); 32 33 while ( gradeValue != -1 ) { 34 // add gradeValue to total 35 total = total + gradeValue; 36 37 // add 1 to gradeCounter 38 gradeCounter = gradeCounter + 1; 39 40 // prompt for input and read grade from user 41 grade = window.prompt( 42 "Enter Integer Grade, -1 to Quit:", "0" ); 43 44 // convert grade from a string to an integer 45 gradeValue = parseInt( grade ); 46 } 47
  • 21. average2.html (3 of 3) 48 // Termination phase 49 if ( gradeCounter != 0 ) { 50 average = total / gradeCounter; 51 52 // display average of exam grades 53 document.writeln( 54 "<h1>Class average is " + average + "</h1>" ); 55 } 56 else 57 document.writeln( "<p>No grades were entered</p>" ); 58 // --> 59 </script> 60 </head> 61 62 <body> 63 <p>Click Refresh (or Reload) to run the script again</p> 64 </body> 65 </html>
  • 22. 09/30/15 © Reem Al-Attas 22
  • 23. 09/30/15 © Reem Al-Attas 23 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) Consider problem Make observations Top-down, stepwise refinement
  • 24. analysis.html (1 of 2) 1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <!-- Fig. 8.11: analysis.html --> 6 <!-- Analyzing Exam Results --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Analysis of Examination Results</title> 11 12 <script type = "text/javascript"> 13 <!-- 14 // initializing variables in declarations 15 var passes = 0, // number of passes 16 failures = 0, // number of failures 17 student = 1, // student counter 18 result; // one exam result 19 20 // process 10 students; counter-controlled loop 21 while ( student <= 10 ) { 22 result = window.prompt( 23 "Enter result (1=pass,2=fail)", "0" ); 24
  • 25. analysis.html (2 of 2) 25 if ( result == "1" ) 26 passes = passes + 1; 27 else 28 failures = failures + 1; 29 30 student = student + 1; 31 } 32 33 // termination phase 34 document.writeln( "<h1>Examination Results</h1>" ); 35 document.writeln( 36 "Passed: " + passes + "<br />Failed: " + failures ); 37 38 if ( passes > 8 ) 39 document.writeln( "<br />Raise Tuition" ); 40 // --> 41 </script> 42 43 </head> 44 <body> 45 <p>Click Refresh (or Reload) to run the script again</p> 46 </body> 47 </html>
  • 26. 09/30/15 © Reem Al-Attas 26
  • 27. 09/30/15 © Reem Al-Attas 27
  • 28. 09/30/15 © Reem Al-Attas 28 Assignment Operators Compound assignment operators  Abbreviate assignment expressions
  • 29. 09/30/15 © Reem Al-Attas 29 Assignment Operators Assignment operator Initial value of variable Sample expression Explanation Assigns += c = 3 c += 7 c = c + 7 10 to c -= d = 5 d -= 4 d = d - 4 1 to d *= e = 4 e *= 5 e = e * 5 20 to e /= f = 6 f /= 3 f = f / 3 2 to f %= g = 12 g %= 9 g = g % 9 3 to g Fig. 8.12 Arithmetic assignment operators.
  • 30. 09/30/15 © Reem Al-Attas 30 Increment and Decrement Operators Preincrement or predecrement operator  Increment or decrement operator placed before a variable Postincrement or postdecrement operator  Increment or decrement operator placed after a variable
  • 31. 09/30/15 © Reem Al-Attas 31 Increment and Decrement Operators Operator Called Sample expression Explanation ++ preincrement ++a Increment a by 1, then use the new value of a in the expression in which a resides. ++ postincrement a++ Use the current value of a in the expression in which a resides, then increment a by 1. -- predecrement --b Decrement b by 1, then use the new value of b in the expression in which b resides. -- postdecrement b-- Use the current value of b in the expression in which b resides, then decrement b by 1. Fig. 8.13 increment and decrement operators.
  • 32. increment.html (1 of 2) 1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <!-- Fig. 8.14: increment.html --> 6 <!-- Preincrementing and Postincrementing --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Preincrementing and Postincrementing</title> 11 12 <script type = "text/javascript"> 13 <!-- 14 var c; 15 16 c = 5; 17 document.writeln( "<h3>Postincrementing</h3>" ); 18 document.writeln( c ); // print 5 19 // print 5 then increment 20 document.writeln( "<br />" + c++ ); 21 document.writeln( "<br />" + c ); // print 6 22 23 c = 5; 24 document.writeln( "<h3>Preincrementing</h3>" ); 25 document.writeln( c ); // print 5
  • 33. 09/30/15 © Reem Al-Attas 33 increment.html (2 of 2) 26 // increment then print 6 27 document.writeln( "<br />" + ++c ); 28 document.writeln( "<br />" + c ); // print 6 29 // --> 30 </script> 31 32 </head><body></body> 33 </html>
  • 34. 09/30/15 © Reem Al-Attas 34 Increment and Decrement Operators Operator Associativity Type ++ -- right to left unary * / % left to right multiplicative + - left to right additive < <= > >= left to right relational == != left to right equality ?: right to left conditional = += -= *= /= %= right to left assignment Fig. 8.15 Precedence and associativity of the operators discussed so far.
  • 35. 09/30/15 © Reem Al-Attas 35 Note on Data Types Loosely typed  Automatically converts between values of different types
  • 36. 09/30/15 © Reem Al-Attas 36 Assignment 6  1) Repeat Ex # 7.26 -solved before- using Loops.  2) Exercise # 8.13 in the text book. Due Date for A# 5&6:  Monday before your lecture.

Editor's Notes

  1. Building Blocks: Data Types, Literals, and Variables. Program-construction principles: Specification, Design, Implementation