Java Script Example for WHILE Loop
<html >
<head>
<title>JavaScript While Loop</title>
<script type="text/javascript">
var myarray=new Array(5);
myarray[0]="Sonam";
myarray[1]="Jamtsho";
myarray[2]="Karma";
myarray[3]="Phuntsho";
myarray[4]="Tshering";
var name=prompt("Enter a name to search:");
var i=0;
while(i<myarray.length)
{
if(name==myarray[i])
{
document.write(name+ " is located at position "+(i+1));
break;
}
i++;
}
</script>
</head>
<body>
</body>
</html>
<head>
<title>JavaScript While Loop</title>
<script type="text/javascript">
var myarray=new Array(5);
myarray[0]="Sonam";
myarray[1]="Jamtsho";
myarray[2]="Karma";
myarray[3]="Phuntsho";
myarray[4]="Tshering";
var name=prompt("Enter a name to search:");
var i=0;
while(i<myarray.length)
{
if(name==myarray[i])
{
document.write(name+ " is located at position "+(i+1));
break;
}
i++;
}
</script>
</head>
<body>
</body>
</html>
Comments
Post a Comment