学过C语言的人,对此应该熟悉,完全是一样的,一个简单的while循环例子:
简单的while循环
<html>
<head>
<title>简单的while循环例子</title>
<script language="javascript">
<!--hide me
var password="tograce";
var answer;
while (answer!=password)
{
answer=prompt("input the password(tograce)","");
}
//show me-->
</script>
</head>
<body>
</body>
</html>
下面代码功能是一样的:
while loop
var a_line="";
var loop = 0;
while (loop < width)
{
a_line = a_line + "x";
loop=loop+1;
}
for loop
var a_line="";
for (var loop=0; loop < width; loop++)
{
a_line = a_line + "x";
}