Page 380 - Webapplication11_C11_Flipbook
P. 380
var sum = 0;
var number = 0;
do {
number = parseInt(prompt("Enter a number: "));
sum=sum+number;
} while(number >= 0);
document.write("The sum is "+sum);
</script>
</body> </html>
2. What will be the output of the following code?
<html>
<body text="red">
<h2 style="color:blue;">Using the for...in loop</h2>
<script>
var string1="Artist";
for (i in string1) {
document.write("<br>"+ string1[i]);
}
</script>
</body>
</html>
#Critical Thinking
Video Session
Scan the QR code or visit the following link to watch the videos: #12 JavaScript Tutorial | While loop -
https://www.youtube.com/watch?v=osOEz3SwyVk
Now try out the same program shown in the video (display first 5 odd numbers) on your own using a
while loop
Watch the video #13 JavaScript Tutorial | Do While loop -
https://www.youtube.com/watch?v=zGG56ae5_GM
........................................................................................................................................................................
........................................................................................................................................................................
4.24 JUMP STATEMENTS IN JAVASCRIPT
Sometimes, there is a situation when the control of the program needs to be transferred out of the loop body, even
if all the values of the iterations of the loop have not been completed. For this purpose, jump statements are used in
JavaScript. JavaScript offers two jump statements—break and continue.
You have already seen the use of break to exit the switch statement. You can also use the break statement to “jump
out” of a loop.
378 Touchpad Web Applications-XI

