Page 154 - DCAP408_WEB_PROGRAMMING
P. 154

Web Programming




                    Notes                        while  (i<=5);
                                                        </script>
                                                 </body>
                                          </html>
                                   Output
                                   The number is 0
                                   The number is 1
                                   The number is 2

                                   The number is 3
                                   The number is 4
                                   The number is 5
                                   Explanation:

                                   i equal to 0.
                                   The loop will run
                                   i will increase by 1 each time the loop runs.
                                   While i is less than, or equal to, 5, the loop will continue to run.

                                   5.6.4  Break

                                   The break statement will break the loop and continue executing the code that follows after the
                                   loop (if any).


                                          Example: Break example.
                                   <html>
                                   <body>
                                   <script  type=”text/javascript”>
                                   var  i=0;
                                   for  (i=0;i<=10;i++)
                                    {
                                     if  (i==3)
                                    {
                                   break;
                                    }
                                   document.write(“The  number  is”  +  i);
                                   document.write(“<br  />”);
                                   }
                                   </script>
                                   </body>
                                   </html>




          148                               LOVELY PROFESSIONAL UNIVERSITY
   149   150   151   152   153   154   155   156   157   158   159