Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 103 - 2625 PortGPt V2.1
P. 103

    Tech Fact

                           Any non-zero value in the while loop indicates always a true condition, whereas zero
                                                     indicates always-false condition.

                             Let’s catch uP

                       What will be the output of the following JavaScript code:
                       var i = 0

                       while (i == 0){
                       document.write("Hello Touchpad");}

                       ________________________________________________________________________________

                            THE DO-WHILE STATEMENT

                     initialisation_expression;
                     do
                     {

                        //Loop body
                         update_expression;
                     } while (conditional_expression);
                     Where,

                     •  initialisation_expression: In this expression, a variable is initialized outside the loop.
                     •  update_expression: The loop control variable is updated here.

                     •   conditional_expression: Similar to for loop, this expression contains a logical condition which
                         evaluates either True or False.

                     For example,

                         int i, s = 0;
                         i = 1;
                         do
                         {

                           s = s + i;
                           i++;
                         }
                         while(i <= 5);

                                                                                                   Loops in JavaScript  101

| 98 99 100 101 102 103 104 105 106 107 108 |