Welcome to Home.

Wednesday, July 8, 2015

Loops in JavaScript

looping statements are used to execute the same block of code in a specified number of times. A while loo runs the same block of codes while or until a condition is true. A do while loop runs once before the condition is checked. If the checked is true, it will continue to run until the condition is false.
(The difference between while and do while loop is that, do while runs once whether or not the condition is meet or true).
A for loop runs the same block of code at a specified number of times.
While loop: In while loop, a block of code is executed if the condition is true and for as long as that condition remains true.
Syntax:
While(condition)
{
                Conditions to be executed
}
Do while: A do while loop executes a block of code once and then checks a condition for as long as the condition is true, it continues to loop. So,whether the condition is true or false , the loop runs at least once.
Syntax:
Do
{
                codes to be executed
}
While(condition)
For Loop: For statement executes a block of code at a specified number of times. It is used when we want to specifiy how many times we want the code to be executed.
Syntax:
                For(a;b;c;)
                {
                                Codes to be executed
                }
Where
                 A= initizalation
                B= declaration

                C=increament / decrement of variable

No comments:

Post a Comment