Web Programming Training By OM SIR Call for free Demo :9320957717/18

JAVA-SCRIPT LOOP

FOR LOOP  CONCEPT:

For loop Syntax:

Syntax:

The syntax of for loop is JavaScript is as follows −
for (initialization; test condition; iteration statement){
   Statement(s) to be executed if test condition is true
}



for loop example:

<html>
   <body>
     
      <script type="text/javascript">
    
            var count;
            document.write("Starting Loop" + "<br />");
        
            for(count = 0; count < 10; count++){
               document.write("Current Count : " + count );
               document.write("<br />");
            }
        
            document.write("Loop stopped!");
   
      </script>
     
      <p>Set the variable to different value and then try...</p>
   </body>
</html>

While LOOP concept:



while  loop syntax:

The syntax of while loop in JavaScript is as follows −

while (expression){
   Statement(s) to be executed if expression is true
}


while loop example:

<html>
  <body>
   <script type="text/javascript">
        
            var count = 0;
            document.write("Starting Loop ");
        
            while (count < 10){
               document.write("Current Count : " + count + "<br />");
               count++;
            }
         document.write("Loop stopped!");
         </script>
      </body>
</html>


Do While  Loop  Concept:



Do while syntax:

Syntax

The syntax for do-while loop in JavaScript is as follows −
do{
   Statement(s) to be executed;
} while (expression);

Note − Don’t miss the semicolon used at the end of the do...while loop.

do while  example:

<html>
   <body>
   <script type="text/javascript">
        
            var count = 0;
           
            document.write("Starting Loop" + "<br />");
            do{
               document.write("Current Count : " + count + "<br />");
               count++;
            }
           
            while (count < 5);
            document.write ("Loop stopped!");
        </script>
     </body>
</html>

Previous
Next Post »