HTML文件,建议用Visual Studio Code或者HBuilder X打开查看
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>while</title>
<script>
var 条件表达式, 循环体;
while (条件表达式) {
循环体
}
//案例一:打印一个人的一生
var age = 0;
while (age <= 100) {
if (age == 0)
console.log('这个人今年出生了');
else if (age == 100) {
console.log('这个人今年去世了享年100岁');
} else {
console.log('这个人今年' + age + '岁了');
}
age++;
}
//案例二:你爱我吗;
/* var str = '';
while (str != '我爱你') {
str = prompt('说你爱我');
} */
</script>
</head>
<body>
</body>
</html>