Tutorial 12 Working with Arrays, Loops, and Conditional Statements

Slides:



Advertisements
Similar presentations
How SAS implements structured programming constructs
Advertisements

Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
1 JavaScript: Control Structures II. 2 whileCounter.html 1 2
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Tutorial 16 Working with Dynamic Content and Styles.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Arrays, Conditionals & Loops in Java. Arrays in Java Arrays in Java, are a way to store collections of items into a single unit. The array has some number.
UNIT II Decision Making And Branching Decision Making And Looping
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Arrays and Control Structures CST 200 – JavaScript 2 –
Decisions, Loops, and Arrays Achmad Arwan, S.Kom.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
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.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
LOGO Conditional Statements & Loops in JavaScript CHAPTER 10 Eastern Mediterranean University School of Computing and Technology Department of Information.
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.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
การสคริปท์ฝั่งลูกข่ายด้วย JavaScript การเขียนโปรแกรมเว็บ.
JavaScript, Fourth Edition
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CIS 133 Mashup Javascript, jQuery and XML Chapter 3 Building Arrays and Controlling Flow.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Working with Loops, Conditional Statements, and Arrays.
CSI 3125, Preliminaries, page 1 Control Statements.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
CSD 340 (Blum)1 For Loops See Beginning JavaScript (Paul Wilton) p. 87.
1 CS428 Web Engineering Lecture 13 Flow Control & Loops (JavaScript - III)
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
JavaScript and Ajax (Control Structures) Week 4 Web site:
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
JavaScript, Sixth Edition
Arrays and Loops. Learning Objectives By the end of this lecture, you should be able to: – Understand what a loop is – Appreciate the need for loops and.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Learning Javascript From Mr Saem
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
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.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Loops in Java.
Ch 7: JavaScript Control Statements I.
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
ITM 352 Flow-Control: Loops
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
FLOW OF CONTROL.
Objectives Create an array Work with array properties and methods
Chapter (3) - Looping Questions.
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Loops and Arrays in JavaScript
How to allow the program to know when to stop a loop.
G6DICP - Lecture 5 Control Structures.
Presentation transcript:

Tutorial 12 Working with Arrays, Loops, and Conditional Statements

Objectives Create an array Populate and reference values from an array Work with array methods Work with For loops Work with While loops New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Objectives Loop through the contents of an array Work with If, If... Else, and multiple conditional statements Use arrays, loops, and conditional statements to create a table Work with break, continue, and label commands New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Working with Arrays An array is a collection of data values organized under a single name Each individual data value is identified by an index To create an array: var array = new Array(length); To populate an array: array[i] = value; var array = [values]; To create and populate an array: var array = new Array(values); New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Specifying Array Length To determine the size of an array, use the property: array.length To add more items to an array, run the command: array[i] = value; To remove items from an array, run the command: array.length = value; New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Using Array Methods New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Working with Program Loops A program loop is a set of commands that is executed repeatedly until a stopping condition has been met For loop A counter variable tracks the number of times a set of commands is run The collection of commands that is run each time through a loop is collectively known as a command block New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Working with Program Loops For loops are often used to cycle through the different values contained within an array New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Working with Program Loops A while loop does not depend on the value of a counter variable; it runs as long as a specific condition is met New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Creating Program Loops To create a For loop, use the syntax: for (start; continue; update) { commands } To create a While loop, use the following syntax: while (continue) { New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Creating Program Loops To create a Do/While loop, use the following syntax: do { commands } while (continue); To loop through the contents of an array, enter the For loop: for (var i = 0; i < array.length; i++) { commands involving array[i] New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Working with Conditional Statements A conditional statement is a statement that runs a command or command block only when certain circumstances are met New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Working with Conditional Statements To test a single condition, use the construction: if (condition) { commands } To test between two conditions, use the following construction: commands if condition is true } else { commands if otherwise New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Working with Conditional Statements To test multiple conditions, use the construction: if (condition 1) { first command block } else if (condition 2) { second command block } else if (condition 3) { third command block } else { default command block } New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Creating a Switch Statement To create a Switch statement to test for different values of an expression, use the structure: switch (expression) { case label1: commands1 break; case label2: commands2 case label3: commands3 ... default: default commands } New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Managing Program Loops and Conditional Statements The break command terminates any program loop or conditional statement The syntax for the break command is: break; The continue command stops processing the commands in the current iteration of the loop and jumps to the next iteration continue; New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Managing Program Loops and Conditional Statements Labels are used to identify statements in JavaScript code so that you can reference those statements elsewhere in a program label: statement break label; continue label; New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

Using Multidimensional Arrays A matrix is a multidimensional array in which each item is referenced by two or more index values In a matrix, each value is referenced by a row index number and column index number Although matrices are commonly used in various programming languages, JavaScript does not support them New Perspectives on HTML, XHTML, and Dynamic HTML, 4e