Tutorial 12 Working with Arrays, Loops, and Conditional Statements

Slides:



Advertisements
Similar presentations
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
Advertisements

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 12 Working with Arrays, Loops, and Conditional Statements
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
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.
CIS 375—Web App Dev II JavaScript II.
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.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
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, 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.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
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.
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
JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.
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.
Web Systems & Technologies
Chapter 6: Loops.
REPETITION CONTROL STRUCTURE
Loops in Java.
Ch 7: JavaScript Control Statements I.
Chapter 2.2 Control Structures (Iteration)
Chapter 6: Conditional Statements and Loops
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
Week#2 Day#1 Java Script Course
JavaScript: Control Statements I
ITM 352 Flow-Control: Loops
Introducing Do While & Do Until Loops & Repetition Statements
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Arrays, For loop While loop Do while loop
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?
CMPE212 – Reminders The other four assignments are now posted.
Loops and Arrays in JavaScript
How to allow the program to know when to stop a loop.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Chapter 8 JavaScript: Control Statements, Part 2
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 Repeat commands using for loops Loop through the contents of an array Repeat commands with while loops New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Objectives Work with ECMASScript5 array methods Create conditional commands with if and if else statements Use arrays, loops, and conditional statements to create a table Interrupt loops with break, continue, and label commands New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Creating Arrays New Perspectives on HTML, CSS, and Dynamic HTML, 5e

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; To create and populate an array: var array = new Array(values); New Perspectives on HTML, CSS, and Dynamic HTML, 5e

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; where value is an integer that is smaller than the highest index currently in the array New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Methods of JavaScript Arrays New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Using Program Loops New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Working with Program Loops A program loop is a set of commands executed repeatedly until a stopping condition has been met For loop A counter variable tracks the number of times a block of commands is run New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Working with Program Loops New Perspectives on HTML, CSS, and Dynamic HTML, 5e

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

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, CSS, and Dynamic HTML, 5e

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, CSS, and Dynamic HTML, 5e

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, CSS, and Dynamic HTML, 5e

Array Methods with ECMAScript 5 Program loops are often used with arrays, and starting with ECMAScript 5—the version of JavaScript developed for HTML5—several new methods were introduced to allow programmers to loop through the contents of an array without having to create a program loop structure Each of these methods is based on calling a function that will be applied to the array and its contents array.method(function) New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Array Methods with ECMAScript 5 New Perspectives on HTML, CSS, and Dynamic HTML, 5e

Conditional Statements New Perspectives on HTML, CSS, and Dynamic HTML, 5e

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, CSS, and Dynamic HTML, 5e

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, CSS, and Dynamic HTML, 5e

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, CSS, and Dynamic HTML, 5e

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, CSS, and Dynamic HTML, 5e

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

Managing Program Loops and Conditional Statements Statement 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, CSS, and Dynamic HTML, 5e