Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 101 - 2625 PortGPt V2.1
P. 101

    </SCRIPT>

                     </BODY>
                     </HTML>
                     Output of the Program 1 is:

                            THE WHILE STATEMENT

                     The while statement or loop is used to repeat a set of instructions until a conditional expression
                     returns True. Once the expression returns False, the loop is terminated. Following is the syntax of
                     the while loop in JavaScript:

                     initialisation_expression;

                     while (conditional_expression) {
                        //loop body
                        update_expression;

                     }
                     Where,

                     •  initialisation_expression: In this expression, a variable is initialized. Unlike for loop, this section
                         appears outside the loop.
                     •  conditional_expression: Similar to for loop, this expression contains a logical condition which
                         evaluates either True or False.

                     •  update_expression: The loop control variable is updated here.
                     For example,

                     i = 0;

                     while(i<5)
                     {
                         document.write(i);
                         i++;

                     }

                                                                                                   Loops in JavaScript  99

| 96 97 98 99 100 101 102 103 104 105 106 |