Page 103 - PortGPT_V2.1_C8_Flipbook
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

