Looping Statement

Advertisements

Prev Tutorial Next Tutorial

Looping Statement in

Set of instructions given to the compiler to execute set of statements until condition becomes false is called loops. The basic purpose of loop is code repetition.

The way of the repetition will be forms a circle that's why repetition statements are called loops. Some loops are available In JavaScript which are given below.

  • while loop
  • for loop
  • do-while

while loop

When we are working with while loop always pre-checking process will be occurred. Pre-checking process means before evolution of statement block condition part will be executed. While loop will be repeats in clock wise direction.

while loop

Syntax

while (condition) 
{
code block to be executed
}

Example of while loop

<script>  
var i=10;  
while (i<=13)  
{  
document.write(i + "<br/>");  
i++;  
}  
</script>

Result

10
11
12
13

do-while loop

In implementation when we need to repeat the statement block at least 1 then go for do-while. In do-while loop post checking of the statement block condition part will be executed.

do while loop

syntax

do
{  
code to be executed 
increment/decrement
}
while (condition); 

Example of do-while loop

Example

<script>  
var i=11;  
do{  
document.write(i + "<br/>");  
i++;  
}while (i<=15);  
</script> 

Result

11
12
13
14
15

for Loop

For loop is a simplest loop first we initialized the value then check condition and then increment and decrements occurred.

for loop

Steps of for loop

for loop step

Syntax

for (initialization; condition; increment/decrement)
{
code block to be executed
}

Example of for loop

Example

<script>  
for (i=1; i<=5; i++)  
{  
document.write(i + "<br/>")  
}  
</script>

Result

1
2
3
4
5

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet


For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements