Page 334 - Web Applications (803) Class 11
P. 334

Output:


































              Difference Between while and do…while Loops
              Though the do while loop and the while loop appear to be identical, they differ in how they are implemented.


                                      while loop                                    do…while loop
                   The condition is tested at the start of the loop in a while  The do while loop tests the condition at the end of the
                   loop, and if the condition is True, statements inside the  loop.  So,  even  if  the  condition  fails,  do  while  runs  the
                   loop are executed. It signifies that the while loop will only  statements in the code block at least once.
                   run the code block if the condition is True.
                   Also called an entry-controlled loop            Also called an exit-controlled loop
                   Minimum no. of iterations—0                     Minimum no. of iterations—1


              Nested Loop

              When a loop is used inside another loop then it is called a nested loop. All the three loops (for, while and do-while)
              provided by JavaScript can be used as nested loop. Syntax to use nested loop is:
                 Outer loop
                 {
                 Inner loop
                 {
                 //Statements to be executed in the inner loop
                 }
                 //Statements to be executed in the outer loop
                 }
              Example:
                 <HTML>
                 <HEAD>
                 <TITLE> Nested Loop </TITLE>

                332     Touchpad Web Applications-XI
   329   330   331   332   333   334   335   336   337   338   339