Thursday, 3 July 2014

Lecture # 11

Following Topics were covered in Eleventh Lecture:
  • for loop
  • while loop
  • do-while loop

Example of for loop:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var num=prompt("Enter a number");

for (var i=1;i<11;i++)
{
 pro=num*i;
 document.write(num + " x " + i + " = " + pro);
 document.write("<br/>");
}
</script>

</head>
</html>

Example of while loop:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var num=prompt("Enter a number");
var i=1;
while(i<11)
{
 pro=num*i;
 document.write(num + " x " + i + " = " + pro);
 document.write("<br/>");
 i++;
}
</script>

</head>
</html>

Example of do-while loop:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var num=prompt("Enter a number");
var i=1;
do
{
 pro=num*i;
 document.write(num + " x " + i + " = " + pro);
 document.write("<br/>");
 i++;
}
while(i<11)
</script>

</head>
</html>

No comments:

Post a Comment