JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Switch code for Lab 4.2 switch (input) { /* input is a variable that we will test. */ case 'M': printf("The prefix is equal to 1E6.\n"); break; case 'k':
Fundamental of C programming
ISP 121 Algorithmsand Computer Programming. Why Know Simple Programming?  You can create powerful macros in Access / Excel / Word / ??? to manipulate.
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
Conditional Statements and Loops. Today’s Learning Goals … Learn about conditional statements and their structure Learn about loops and their structure.
Creating PHP Pages Chapter 7 PHP Decisions Making.
1 CS101 Introduction to Computing Lecture 23 Flow Control & Loops (Web Development Lecture 8)
آموزش طراحی وب سایت جلسه یازدهم – جاوا اسکریپت 2 تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: پست الکترونیک :
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.
HTML Forms JavaScript Introduction / Overview Lab Homework #1 CS 183 4/8/2010.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
آموزش طراحی وب سایت جلسه دهم – جاوا اسکریپت 1 تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: پست الکترونیک :
Client-Side programming with JavaScript 3
Arrays and Control Structures CST 200 – JavaScript 2 –
Decisions, Loops, and Arrays Achmad Arwan, S.Kom.
Loops Doing the same thing over and over and over and over and over and over…
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
Conditional Statements While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make.
JavaScript – part II. The if Statement if (condition) { block of code to be executed if the condition is true }
1 JavaScript 1. 2 Java vs. JavaScript Java –Is a high level programming language –Is platform independent –Runs on a standardized virtual machine.
CIS 375—Web App Dev II JavaScript II.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
VBScript. Introduction Visual Basic scripting language is client side scripting language. It is developed by Microsoft VBScript is subset of VB language.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
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.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
JavaScript Jordan Clark, Jamie Kapilivsky, Taylor Monk, Jessica Torres.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
VBScript Conditional Statements. Conditional Statements Very often when you write code, you want to perform different actions for different decisions.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
In God we trust Learning Java Script. Java Script JavaScript is the scripting language of the Web! JavaScript is used in millions of Web pages to improve.
JavaScript Lectures Level 7. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting.
Web Development JavaScript. Introduction to JavaScript.
CSI 3125, Preliminaries, page 1 Control Statements.
1 CS428 Web Engineering Lecture 13 Flow Control & Loops (JavaScript - III)
Chapter 9: Control Statements II CIS 275—Web Application Development for Business I.
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
JavaScript, Sixth Edition
Learning Javascript From Mr Saem
 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.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Pertemuan 3 JavaScript.
CHAPTER 4 DECISIONS & LOOPS
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Unit-1 Introduction to Java
My First Web Page document.write("" + Date() + ""); To insert.
CiS 260: App Dev I Chapter 4: Control Structures II.
Ch 7: JavaScript Control Statements I.
Chapter 6: Conditional Statements and Loops
Expressions and Control Flow in JavaScript
JavaScript: Control Statements I
IF if (condition) { Process… }
Pertemuan 3 JavaScript.
My First Web Page document.write("" + Date() + ""); To insert.
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Computer Science Core Concepts
Conditional Statements & Loops in JavaScript
Program Flow.
BIT116: Scripting Lecture 6 Part 1
How to allow the program to know when to stop a loop.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Presentation transcript:

JavaScript JavaScript ( Condition and Loops )

Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition is true } //If the time is less than 10, you will get a "Good morning" greeting. //Otherwise you will get a "Good day" greeting. var d = new Date(); var time = d.getHours(); if (time

If...else if...else Statement ( Sample Program) var d = new Date(); var time = d.getHours(); if (time<10) { document.write(" Good morning "); } else if (time>=10 && time<16) { document.write(" Good day "); } else { document.write(" Hello World! "); } This example demonstrates the if..else if...else statement.

The JavaScript Switch Statement (Sample Program) Use the switch statement to select one of many blocks of code to be executed. var d=new Date(); var theDay=d.getDay(); switch (theDay) { case 5: document.write(" Finally Friday "); break; case 6: document.write(" Super Saturday "); break; case 0: document.write(" Sleepy Sunday "); break; default: document.write(" I'm really looking forward to this weekend! "); } This JavaScript will generate a different greeting based on what day it is. Note that Sunday=0, Monday=1, Tuesday=2, etc.

The break / continue Statement The break statement will break the loop and continue executing the code that follows after the loop (if any). Sample Program:- var i=0; for (i=0;i "); } The continue Statement – The continue statement will break the current loop and continue with the next value. Sample Program :- Same as above accept on the place of break write continue;.

The while Loop The while loop loops through a block of code while a specified condition is true. var i=0; while (i "); i++; }

The do...while Loop The do...while loop is a variant( البديل ) of the while loop. This loop will execute the block of code ONCE, and then it will repeat the loop as long as the specified condition is true. Sample Code :- i = 0; do { document.write("The number is " + i); document.write(" "); i++; } while (i <= 5); Explanation: i equal to 0. The loop will run i will increase by 1 each time the loop runs. While i is less than, or equal to, 5, the loop will continue to run.