ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 4 Client Side Scripting JavaScript Looping.

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Advertisements

Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Control Flow Statements: Repetition/Looping
Looping Structures: Do Loops
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Types of selection structures
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Java review and more. Class Header  Public class Welcome  Case sensitive  Body of the class must be enclosed by braces.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Outline 14.1Introduction 14.2Algorithms 14.3Pseudocode 14.4Control Structures 14.5The if Selection.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 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.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 5 Server Side Scripting Perl.
USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,
Previously Repetition Structures While, Do-While, For.
9/20: The while Repetition Structure last time’s program repetition structures: what they are the while repetition structure homework due on Thursday program.
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 17 - WMLScript: Control Structures I Outline 17.1 Introduction 17.2 Algorithms 17.3 Pseudocode.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
 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.
JavaScript Syntax, how to use it in a HTML document
1 JavaScript: Control Structures. 2 Control Structures Flowcharting JavaScript’s sequence structure.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
JavaScript Dynamic Active Web Pages Client Side Scripting.
MTA EXAM HTML5 Application Development Fundamentals.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
BLOCK  is enclosed by curly brackets {}.  Keep in mind that blocks are always bounded by curly brackets, even if your block has only one code line.
Learning Javascript From Mr Saem
1 JavaScript/Jscript 2 Control Structures I. 2 Introduction Before programming a script have a –Thorough understanding of problem –Carefully planned approach.
CS346 Javascript-41 Module 4 JavaScript Functions.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
CHAPTER 4 DECISIONS & LOOPS
Chapter 10 Programming Fundamentals with JavaScript
JavaScript: Control Structures I
while Repetition Structure
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
JavaScript: Control Statements I
Week 4 – Chapter 3 Repetition.
Ch 7: JavaScript Control Statements I.
JavaScript: Control Statements.
Chapter 19 JavaScript.
Loop Control Structure.
JavaScript Selection Statement Creating Array
Chapter 10 Programming Fundamentals with JavaScript
Chapter 8 - JavaScript: Control Structures I
Alice in Action with Java
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Let’s all Repeat Together
A LESSON IN LOOPING What is a loop?
Program Flow.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Tutorial 10: Programming with javascript
Loops.
CSCI 1100/1202 February 6, 2002.
Chapter 8 - JavaScript: Control Structures I
Week 3 – Repetition (ctd.)
Presentation transcript:

ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 4 Client Side Scripting JavaScript Looping

Types of Looping While Do While For

While Statement loops through a block of code while a condition is true Syntax while (condition) { code to be executed } JavaScript is case sensitive while ≠ WHILE N.B. All JavaScript reserved keywords are case sensitive After the while statement is executed program flows to the next statement after the while is finished

While Statement ctd. The while statement can be used in 2 ways 1.) The number of repetitions is known in advance e.g. calculating the average of a class. Class Average Program var total, gradeCounter, gradeValue, average, grade; total = 0; gradeCounter =1;

While Statement ctd. while (gradeCounter <=10) { grade = window.prompt (“Enter integer grade:”, “0”); gradeValue = parseInt(grade); total = total +gradeValue; gradeCounter = gradeCounter + 1; } average = total /10; document.writeln(“ ” Class average is “ +average + “ ”);

While Statement ctd. Some Text Here

While Statement using a sentinel value 2.) Where the number of repetitions is not known in advance. In this scenario a value known as a sentinel value is used as a stopping value. Class Average Program var total, gradeCounter, gradeValue, average, grade; total = 0; gradeCounter =0;

While Statement using a sentinel value grade = window.prompt(“Enter Integer Grade, -1 to Quit:”, “0”); gradeValue = parseInt(grade); while (gradeValue != -1) { total = total + gradeValue; gradeCounter = gradeCounter +1; grade = window.prompt(“Enter Integer Grade, -1 to Quit: “, “0”); gradeValue = parseInt(grade); }

While Statement using a sentinel value if (gradeCounter !=0) { average = total/gradeCounter; document.writeln(“ Class average is “ +average + “ ”); } else { document.writeln(“ Class average is “ +average + “ ”); }

While Statement using a sentinel value Some text

Do While Statement Loops through the block at least once Syntax do { code to be executed } while (condition); example i = 0

Do While ctd. do { document.write("The number is " + i) document.write(" ") i++ } while (i <= 5);

The For Loop run statements a specified number of times Requires: - the name of a control variable - its initial value - the increment/decrement by which the loop counter is modified - the testing condition for the final value

For Loop ctd. Syntax for(initialization; test condition; increment) { code to be executed; } Example Sum the Even Integers from 2 to 100

For Loop ctd var sum = 0; for (var number =2; number<=100; number +2) { sum += number; } document.writeln(“ ”The sum of the even integers “ + “ from 2 to 100 is “ +sum + “ ”);