SlideShare a Scribd company logo
2
Most read
4
Most read
7
Most read
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 (20)

PPTX
Javascript operators
Mohit Rana
 
PPTX
jQuery
Jay Poojara
 
PPTX
Java script
Shyam Khant
 
DOCX
Javascript tutorial
Abhishek Kesharwani
 
PDF
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
PPTX
Javascript functions
Alaref Abushaala
 
PPSX
Introduction to Html5
www.netgains.org
 
PPTX
Html5 and-css3-overview
Jacob Nelson
 
PPTX
Javascript 101
Shlomi Komemi
 
PDF
Javascript
Vibhor Grover
 
PDF
Javascript basics
shreesenthil
 
PDF
Java Programming
Anjan Mahanta
 
PDF
HTML practical file
Kuldeep Sharma
 
PPT
Php forms
Anne Lee
 
PPTX
Static and Dynamic webpage
Aishwarya Pallai
 
PPTX
Client side scripting and server side scripting
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Basics of JavaScript
Bala Narayanan
 
PPT
jQuery
Mostafa Bayomi
 
PPT
Javascript
mussawir20
 
Javascript operators
Mohit Rana
 
jQuery
Jay Poojara
 
Java script
Shyam Khant
 
Javascript tutorial
Abhishek Kesharwani
 
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
Javascript functions
Alaref Abushaala
 
Introduction to Html5
www.netgains.org
 
Html5 and-css3-overview
Jacob Nelson
 
Javascript 101
Shlomi Komemi
 
Javascript
Vibhor Grover
 
Javascript basics
shreesenthil
 
Java Programming
Anjan Mahanta
 
HTML practical file
Kuldeep Sharma
 
Php forms
Anne Lee
 
Static and Dynamic webpage
Aishwarya Pallai
 
Client side scripting and server side scripting
baabtra.com - No. 1 supplier of quality freshers
 
Basics of JavaScript
Bala Narayanan
 
Javascript
mussawir20
 

Similar to JavaScript Looping Statements (20)

DOCX
Loops and iteration.docx
NkurikiyimanaGodefre
 
PPTX
JS Control Statements and Functions.pptx
Ramakrishna Reddy Bijjam
 
PPTX
JavaScript Session 3
Muhammad Ehtisham Siddiqui
 
DOC
Web programming[10]
Muhammad Awaluddin
 
DOCX
Janakiram web
MARELLA CHINABABU
 
PPTX
Loops (Refined).pptx
chimkwuogworordu
 
PPTX
JavaScript Basics
Bhanuka Uyanage
 
PDF
1660213363910.pdf
CuentaTemporal4
 
PPT
JavaScript iteration
Charles Russell
 
PPTX
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
PPTX
While loop and for loop 06 (js)
AbhishekMondal42
 
PPTX
10. session 10 loops and arrays
Phúc Đỗ
 
PPTX
06-Control-Statementskkkkkkkkkkkkkk.pptx
kamalsmail1
 
PPTX
javascriptbasicsPresentationsforDevelopers
Ganesh Bhosale
 
PPTX
Javascript
Gita Kriz
 
PPTX
For
sidneyodingo
 
PDF
Loops in JavaScript
Florence Davis
 
PPT
JavaScript Control Statements II
Reem Alattas
 
PDF
L5, Loop and iteration, CSE 202, BN11.pdf
SauravBarua11
 
PPT
CSIS 138 JavaScript Class3
Teresa Pelkie
 
Loops and iteration.docx
NkurikiyimanaGodefre
 
JS Control Statements and Functions.pptx
Ramakrishna Reddy Bijjam
 
JavaScript Session 3
Muhammad Ehtisham Siddiqui
 
Web programming[10]
Muhammad Awaluddin
 
Janakiram web
MARELLA CHINABABU
 
Loops (Refined).pptx
chimkwuogworordu
 
JavaScript Basics
Bhanuka Uyanage
 
1660213363910.pdf
CuentaTemporal4
 
JavaScript iteration
Charles Russell
 
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
While loop and for loop 06 (js)
AbhishekMondal42
 
10. session 10 loops and arrays
Phúc Đỗ
 
06-Control-Statementskkkkkkkkkkkkkk.pptx
kamalsmail1
 
javascriptbasicsPresentationsforDevelopers
Ganesh Bhosale
 
Javascript
Gita Kriz
 
Loops in JavaScript
Florence Davis
 
JavaScript Control Statements II
Reem Alattas
 
L5, Loop and iteration, CSE 202, BN11.pdf
SauravBarua11
 
CSIS 138 JavaScript Class3
Teresa Pelkie
 
Ad

More from Janssen Harvey Insigne (8)

PDF
Safety and Health Inspection
Janssen Harvey Insigne
 
PDF
Institutional Impact of Spanish Rule in the Philippines
Janssen Harvey Insigne
 
PDF
Intellectual Property Code of the Philippines (RA 8293)
Janssen Harvey Insigne
 
PDF
IBM OS/2 Analysis
Janssen Harvey Insigne
 
PDF
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)
Janssen Harvey Insigne
 
PPTX
Properties of Radio Waves
Janssen Harvey Insigne
 
PDF
Different Types of Network Topologies
Janssen Harvey Insigne
 
PPTX
Paragraph Development (definition)
Janssen Harvey Insigne
 
Safety and Health Inspection
Janssen Harvey Insigne
 
Institutional Impact of Spanish Rule in the Philippines
Janssen Harvey Insigne
 
Intellectual Property Code of the Philippines (RA 8293)
Janssen Harvey Insigne
 
IBM OS/2 Analysis
Janssen Harvey Insigne
 
Ang Buhay at mga Gawa ni Rizal (Life and Works of Rizal)
Janssen Harvey Insigne
 
Properties of Radio Waves
Janssen Harvey Insigne
 
Different Types of Network Topologies
Janssen Harvey Insigne
 
Paragraph Development (definition)
Janssen Harvey Insigne
 
Ad

Recently uploaded (20)

PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 

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>