SlideShare a Scribd company logo
1 of 18
Download to read offline
Web App Programming (CpET12L)
JavaScript
Looping
Statements
JAVASCRIPT LOOPING STATEMENTS …..
Looping is a feature that facilitates the execution of a
set of instructions/functions repeatedly while some
condition evaluates to true. Very often when you write code,
you want the same block of code to run a number of times.
You can use looping statements in your code to do this.
Loops are used in JavaScript to perform repeated tasks based
on a condition. Conditions typically return true or false when
analysed. A loop will continue running until the defined
condition returns false.
JAVASCRIPT LOOPING STATEMENTS …..
In JavaScript, we have the following
looping statements:
• for loop - run statements a specified number of times
>> for…in
>> for…of
• while loop - loops through a block of code while a condition is
true
• do…while loop - loops through a block of code once, and then
repeats the loop while a condition is true
JAVASCRIPT LOOPING STATEMENTS …..
FOR Loop
SYNTAX:
• Statement 1 is executed (one time) before the execution of the code block.
• Statement 2 defines the condition for executing the code block.
• Statement 3 is executed (every time) after the code block has been
executed.
JAVASCRIPT LOOPING STATEMENTS …..
FOR Loop
FLOWCHART:
JAVASCRIPT LOOPING STATEMENTS …..
FOR Loop
EXAMPLE 1:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
for (i=0; i<=5; i++)
{
document.write("<b>The number is " + i + "</b>")
document.write("<br>")
}
</script>
</body>
</html>
JAVASCRIPT LOOPING STATEMENTS …..
FOR Loop
EXAMPLE 2:
<!DOCTYPE html>
<html> <body>
<p id="demo"></p>
<script>
var places = ["Mullingar","Doncaster","Wolverhampton","Cheshire","Bradford"];
var i, len, text;
for (i = 0, len = places.length, text = ""; i < len; i++) {
text += places[i] + "<br>"; }
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
JAVASCRIPT LOOPING STATEMENTS …..
FOR…IN Loop
The for...in statement iterates over the enumerable properties of an
object, in arbitrary order. It loops through the properties of an object.
SYNTAX:
JAVASCRIPT LOOPING STATEMENTS …..
FOR…IN Loop
EXAMPLE:
<!DOCTYPE html>
<html><body>
<p id="demo"></p>
<script>
var txt = "";
var person = {fname:"Georgia", lname:"Rose,", age:21};
var x;
for (x in person) {
txt += person[x] + " ";
}
document.getElementById("demo").innerHTML = txt;
</script>
</body></html>
JAVASCRIPT LOOPING STATEMENTS …..
FOR…OF Loop
The for...of statement creates a loop iterating over iterable objects
(including Array, Map, Set, Arguments object and so on)
SYNTAX:
JAVASCRIPT LOOPING STATEMENTS …..
FOR…OF Loop
EXAMPLE 1: (Looping over an Array)
<!DOCTYPE html>
<html>
<body>
<p> <b> FOR...OF (Looping over an Array) </b> </p>
<script>
var places = ["Mullingar","Doncaster","Wolverhampton","Cheshire","Bradford"];
var x;
for (x of places) {
document.write(x + "<br >");
}
</script>
</body>
</html>
JAVASCRIPT LOOPING STATEMENTS …..
FOR…OF Loop
EXAMPLE 2: (Looping over a String)
<!DOCTYPE html>
<html>
<body>
<p> <b> FOR...OF (Looping over a String) </b> </p>
<script>
var txt = "JavaScript";
var x;
for (x of txt) {
document.write(x + "<br >");
}
</script>
</body>
</html>
JAVASCRIPT LOOPING STATEMENTS …..
WHILE Loop
The while loop starts by evaluating the condition. If the condition is true,
the statement(s) is/are executed. If the condition is false, the statement(s)
is/are not executed.After that, while loop ends.
SYNTAX:
JAVASCRIPT LOOPING STATEMENTS …..
WHILE Loop
FLOWCHART:
JAVASCRIPT LOOPING STATEMENTS …..
WHILE Loop
EXAMPLE:
<!DOCTYPE html>
<html><body>
<p id="demo"></p>
<script>
var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}
document.getElementById("demo").innerHTML = text;
</script>
</body></html>
JAVASCRIPT LOOPING STATEMENTS …..
DO…WHILE Loop
The do/while loop is a variant of the while loop.This loop will execute the
code block once, before checking if the condition is true, then it will repeat
the loop as long as the condition is true.
SYNTAX:
JAVASCRIPT LOOPING STATEMENTS …..
DO…WHILE Loop
FLOWCHART:
JAVASCRIPT LOOPING STATEMENTS …..
DO…WHILE Loop
EXAMPLE:
<!DOCTYPE html>
<html> <body>
<p id="demo"></p>
<script>
var text = ""
var i = 0;
do {
text += "<br>Number " + i;
i++;
}
while (i < 10);
document.getElementById("demo").innerHTML = text;
</script>
</body> </html>

More Related Content

What's hot

JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS PresentationShawn Calvert
 
javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 
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!
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation Salman Memon
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScript9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScriptpcnmtutorials
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Propertieshstryk
 

What's hot (20)

JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
HTML5
HTML5HTML5
HTML5
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
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
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
jQuery
jQueryjQuery
jQuery
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
Loops in java script
Loops in java scriptLoops in java script
Loops in java script
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScript9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScript
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Properties
 

Similar to JavaScript Looping Statements

Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoftch samaram
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arraysPhúc Đỗ
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta Semenistyi"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta SemenistyiBinary Studio
 
JavaScript Interview Questions 2023
JavaScript Interview Questions 2023JavaScript Interview Questions 2023
JavaScript Interview Questions 2023Laurence Svekis ✔
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Javascript basics
Javascript basicsJavascript basics
Javascript basicsFin Chen
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptxMuqaddarNiazi1
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second LanguageRob Dunn
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of ClojureDavid Leung
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioAndrey Karpov
 
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And BeyondMike Fogus
 

Similar to JavaScript Looping Statements (20)

Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta Semenistyi"JS: the right way" by Mykyta Semenistyi
"JS: the right way" by Mykyta Semenistyi
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript Interview Questions 2023
JavaScript Interview Questions 2023JavaScript Interview Questions 2023
JavaScript Interview Questions 2023
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of Clojure
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-Studio
 
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And Beyond
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
 

More from Janssen Harvey Insigne

Institutional Impact of Spanish Rule in the Philippines
Institutional Impact of Spanish Rule in the PhilippinesInstitutional Impact of Spanish Rule in the Philippines
Institutional Impact of Spanish Rule in the PhilippinesJanssen Harvey Insigne
 
Intellectual Property Code of the Philippines (RA 8293)
Intellectual Property Code of the Philippines (RA 8293)Intellectual Property Code of the Philippines (RA 8293)
Intellectual Property Code of the Philippines (RA 8293)Janssen Harvey Insigne
 
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)Janssen Harvey Insigne
 

More from Janssen Harvey Insigne (8)

Safety and Health Inspection
Safety and Health InspectionSafety and Health Inspection
Safety and Health Inspection
 
Institutional Impact of Spanish Rule in the Philippines
Institutional Impact of Spanish Rule in the PhilippinesInstitutional Impact of Spanish Rule in the Philippines
Institutional Impact of Spanish Rule in the Philippines
 
Intellectual Property Code of the Philippines (RA 8293)
Intellectual Property Code of the Philippines (RA 8293)Intellectual Property Code of the Philippines (RA 8293)
Intellectual Property Code of the Philippines (RA 8293)
 
IBM OS/2 Analysis
IBM OS/2 AnalysisIBM OS/2 Analysis
IBM OS/2 Analysis
 
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)
 
Properties of Radio Waves
Properties of Radio WavesProperties of Radio Waves
Properties of Radio Waves
 
Different Types of Network Topologies
Different Types of Network TopologiesDifferent Types of Network Topologies
Different Types of Network Topologies
 
Paragraph Development (definition)
Paragraph Development (definition)Paragraph Development (definition)
Paragraph Development (definition)
 

Recently uploaded

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
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
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
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
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
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri 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🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 

JavaScript Looping Statements

  • 1. Web App Programming (CpET12L) JavaScript Looping Statements
  • 2. JAVASCRIPT LOOPING STATEMENTS ….. Looping is a feature that facilitates the execution of a set of instructions/functions repeatedly while some condition evaluates to true. Very often when you write code, you want the same block of code to run a number of times. You can use looping statements in your code to do this. Loops are used in JavaScript to perform repeated tasks based on a condition. Conditions typically return true or false when analysed. A loop will continue running until the defined condition returns false.
  • 3. JAVASCRIPT LOOPING STATEMENTS ….. In JavaScript, we have the following looping statements: • for loop - run statements a specified number of times >> for…in >> for…of • while loop - loops through a block of code while a condition is true • do…while loop - loops through a block of code once, and then repeats the loop while a condition is true
  • 4. JAVASCRIPT LOOPING STATEMENTS ….. FOR Loop SYNTAX: • Statement 1 is executed (one time) before the execution of the code block. • Statement 2 defines the condition for executing the code block. • Statement 3 is executed (every time) after the code block has been executed.
  • 5. JAVASCRIPT LOOPING STATEMENTS ….. FOR Loop FLOWCHART:
  • 6. JAVASCRIPT LOOPING STATEMENTS ….. FOR Loop EXAMPLE 1: <!DOCTYPE html> <html> <body> <script type="text/javascript"> for (i=0; i<=5; i++) { document.write("<b>The number is " + i + "</b>") document.write("<br>") } </script> </body> </html>
  • 7. JAVASCRIPT LOOPING STATEMENTS ….. FOR Loop EXAMPLE 2: <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var places = ["Mullingar","Doncaster","Wolverhampton","Cheshire","Bradford"]; var i, len, text; for (i = 0, len = places.length, text = ""; i < len; i++) { text += places[i] + "<br>"; } document.getElementById("demo").innerHTML = text; </script> </body> </html>
  • 8. JAVASCRIPT LOOPING STATEMENTS ….. FOR…IN Loop The for...in statement iterates over the enumerable properties of an object, in arbitrary order. It loops through the properties of an object. SYNTAX:
  • 9. JAVASCRIPT LOOPING STATEMENTS ….. FOR…IN Loop EXAMPLE: <!DOCTYPE html> <html><body> <p id="demo"></p> <script> var txt = ""; var person = {fname:"Georgia", lname:"Rose,", age:21}; var x; for (x in person) { txt += person[x] + " "; } document.getElementById("demo").innerHTML = txt; </script> </body></html>
  • 10. JAVASCRIPT LOOPING STATEMENTS ….. FOR…OF Loop The for...of statement creates a loop iterating over iterable objects (including Array, Map, Set, Arguments object and so on) SYNTAX:
  • 11. JAVASCRIPT LOOPING STATEMENTS ….. FOR…OF Loop EXAMPLE 1: (Looping over an Array) <!DOCTYPE html> <html> <body> <p> <b> FOR...OF (Looping over an Array) </b> </p> <script> var places = ["Mullingar","Doncaster","Wolverhampton","Cheshire","Bradford"]; var x; for (x of places) { document.write(x + "<br >"); } </script> </body> </html>
  • 12. JAVASCRIPT LOOPING STATEMENTS ….. FOR…OF Loop EXAMPLE 2: (Looping over a String) <!DOCTYPE html> <html> <body> <p> <b> FOR...OF (Looping over a String) </b> </p> <script> var txt = "JavaScript"; var x; for (x of txt) { document.write(x + "<br >"); } </script> </body> </html>
  • 13. JAVASCRIPT LOOPING STATEMENTS ….. WHILE Loop The while loop starts by evaluating the condition. If the condition is true, the statement(s) is/are executed. If the condition is false, the statement(s) is/are not executed.After that, while loop ends. SYNTAX:
  • 14. JAVASCRIPT LOOPING STATEMENTS ….. WHILE Loop FLOWCHART:
  • 15. JAVASCRIPT LOOPING STATEMENTS ….. WHILE Loop EXAMPLE: <!DOCTYPE html> <html><body> <p id="demo"></p> <script> var text = ""; var i = 0; while (i < 10) { text += "<br>The number is " + i; i++; } document.getElementById("demo").innerHTML = text; </script> </body></html>
  • 16. JAVASCRIPT LOOPING STATEMENTS ….. DO…WHILE Loop The do/while loop is a variant of the while loop.This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. SYNTAX:
  • 17. JAVASCRIPT LOOPING STATEMENTS ….. DO…WHILE Loop FLOWCHART:
  • 18. JAVASCRIPT LOOPING STATEMENTS ….. DO…WHILE Loop EXAMPLE: <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var text = "" var i = 0; do { text += "<br>Number " + i; i++; } while (i < 10); document.getElementById("demo").innerHTML = text; </script> </body> </html>