Loops in javascript: Web development tutorial

Javascript Loops in web development:


Loops in js(javascript):



javascript loops tutorial:
Again, you'll find many close similarities between JavaScript and PHP when it
Comes looping. Both languages do and do-while loops doing something.


While loops:

A JavaScript while loop first checks the value of an expression and starts executing it.
The statements inside the loop only if it is true. If it's wrong then hang
Go to the next JavaScript statement (if any)

After completing the loop repetition, the expression is checked again to see if
True, this process continues until the value of the expression is false
Or until the execution is stopped.
Example:
Loop in a while

Counter = 0
While (counter <5)
{

 ("Counter:" + Counter + "<br>")
++ Counter
}

The script has the following results:
Counter: 0
Counter: 1
Counter: 2
Counter: 3
Counter: 4

If the variable counter is not added inside the loop, this is it Some browsers may be irresponsible
A never-ending loop, and tearing this page up can never be easier Minutes with escape or stop button. So be careful with yourself Javascript loops.


Do ... while loops:

When you need to reboot at least once before testing, use
do ... while a loop, which is similar to a while loop, except for the expression of the test
Checked after each iteration of the loop. So, in the first seven results in the production
The table of 7 times, you can use code such as:
Do ... while loop

Count = 1
What
{
count( count1+2+3...6)
} While (++ count <= 7)

As you might expect, this loop has the following results:
1 time 7 7
2 times 7 is 14
3 times 7 is 21
4 times 7 28
5 times 7 is 35
6 times 7 is 42
7 times 7 is 49

For loop:

A for loop combines the best of the world into a single looping construct that allows
You must pass three parameters for each statement. An early expression Condition is an expression of quality if action A modified expression. They are separated by a
 semicolon, such as (expr1; expr2; expr3). The first iteration of the loop, the initial expression comes into operation. In the case of code rules, counting will be started for 7Value 1. Then, each time around the loop, the expression of the condition
(in this case, Count <= 7) is checked and enters the loop only when the condition is true. Finally, At the end of each iteration, the modification expression is executed.


In the case of
(Count = 1; count <= 7; count + ++)
{
 (count + "times is 7" + count * 7 + "<br>");
}
                Ongoing statement
Sometimes you don't want to get out of the loop completely, but instead
Only the rest of the statements for this iteration of the loop. In such cases, you can use it. Continue the command. Example 14-21 shows this in use.
Example of for loop, Using the command issued in the loop



<script>
haystack = new Array ()
haystack [4] = "needle"
haystack [11] = "needle"
haystack [17] = "needle"
for (j = 0; j <20; ++ j)
{
If (grass mark [j] == "needle")
{
Document.Write ("<br> - Found at location" + j + "<br>")
Continue
}
Document.Write (j + ",")
}

</script>

The next tutorial and more knowldege about Engineering, web Designer, and IT information click on related links.
Best Of luck.
Previous
Next Post »