0% found this document useful (0 votes)
12 views10 pages

Deepak Web Tech.pptx

Uploaded by

try.kdverma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views10 pages

Deepak Web Tech.pptx

Uploaded by

try.kdverma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Introduction to

Loops in JavaScript
Loops are a fundamental programming concept in JavaScript,
allowing developers to automate repetitive tasks and create
dynamic, interactive applications. This presentation will explore the
different types of loops available in JavaScript and provide practical
examples to help you master this powerful tool.
What are Loops?

1 Repetitive 2 Automation
Execution
Loops enable the Loops automate
execution of a block of repetitive tasks, saving
code repeatedly, until a time and reducing the
specific condition is met. risk of human error.

3 Efficiency
Loops help write more concise and efficient code, reducing
the overall complexity of a program.
Types of Loops in
JavaScript
For Loop While Loop Do-While Loop
Executes a block of code a Executes a block of code as long as Executes a block of code at least
specified number of times, with a a specified condition is true. once, then continues to execute
counter variable that increments or the block as long as a specified
decrements. condition is true.
For Loop

Syntax

for (initialization; condition; increment/decrement)


{//Codes}
Initialization Increment/
Set the initial value of the loop counter variable. Decrement
Update the loop counter variable after each iteration.

1 2 3

Condition
Specify the condition that must be true for the loop to
continue executing.
Initialization

Code Example: For var i = 0;

Loop
Condition
for (var i = 0; i < 5; i+ i<5
+)
{
Increment
console.log(i); i++

}
This for loop will execute 5 times, logging the values 0, 1, 2, 3, and
Output
4 to the console.
0, 1, 2, 3, 4
While Loop

Syntax

while(condition)
{//Codes}
Condition Update
Specify the condition that must be true for the loop to The loop counter variable must be updated within the loop
continue executing. to
ensure the condition eventually becomes false.

1 2 3

Execution
The block of code inside the loop will be executed as long
as the condition is true.
var i = 0; Code Example: While
while (i < 5) Loop
{
Initialization Condition
var i = 0; i<5
console.log(i);
i++;
}
Increment Output
i++ 0, 1, 2, 3, 4

This while loop will execute 5 times, logging the values 0, 1, 2, 3, and 4 to the console.
Do-While Loop

Guaranteed Execution Commonly Used


The do-while loop will execute the code block Do-while loops are often used when you know
at least once, regardless of the condition. the code block needs to run at least once.

Condition Check
The condition is evaluated after the code block is executed, allowing the loop to continue as long as the
condition is true.
Code Example: Do-While
Loop
let i = 0;
do {
console.log(i);
i++;
} while (i < 5);

Initialization var i = 0;

Condition i<5

Iteration i++

Output 0, 1, 2, 3, 4
Thank you for your
kind attention

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy