Page 110 - PortGPT_V2.1_C8_Flipbook
P. 110
<HEAD>
Factopedia <TITLE> Sum of first 5 natural numbers </TITLE>
</HEAD>
<BODY>
<SCRIPT>
var sum = 0;
for(var i=1; i <= 5; i++)
{
sum = sum + i;
Some programming
}
languages use
document.write("Sum of first 5 natural numbers
semicolon at the end
= ", sum);
of the statement to
terminate it. But in </SCRIPT>
JavaScript, you can </BODY>
start your statement </HTML>
with semicolon.
Let’s Back-uP
JavaScript • In JavaScript, the statements that are used to repeat a set
frameworks are best of instructions are called iterative or looping statements
suited for mobile app or simply loops.
development.
• The for statement or loop is used to repeat an instruction
or a set of instructions for a fixed number of times.
• The while statement or loop is used to repeat a set of
instructions until a conditional expression returns True.
• The do-while loop is used to execute a set of statements
repeatedly, if the number of iterations is not known.
• When a loop is used inside another loop then it is called a
JavaScript is not
allowed Hyphens in nested loop.
the varibale names. • The loop that is never ends is called infinite loop.
Hyphens will be • The break statement halts the execution of a loop and
identified as minus program flow switches to the statement after the loop.
sign. • The continue statement stops the execution of the current
iteration of the loop and sends the control of the program
to the beginning of the loop for next iteration.
108 Premium Edition-VIII

