JavaScript for Loop


Loops execute a block of code a specified number of times, or while a specified condition is true. Often when you write code, you want the same block of code to run over and over again in a row. Instead of adding several almost equal lines in a script we can use loops to perform a task like this. In JavaScript, there are two different kind of loops:
The syntax of for loop is given on the right:
 for ( var=start;  var<=end;  var+=increment ) {
   code to be executed
 }

The script checks whether the entered ID is numeric or not. It uses a for loop to loop through the ID byte by byte. The property length of the object String contains the length of the string. For example,
 var s = "Hello!";
 document.write(
   s.length );
will print a value of 6.



   


Demonstration
The following demonstration shows how the script of HTML and JavaScript is displayed on the Web.

     





      Knowledge is knowing a tomato is a fruit.    
      Wisdom is not putting it in a fruit salad.