非零基础自学前端最后一遍
二 JavaScript基础
6 JavaScript循环语句
6.5 for循环的步骤解析
6.5.1 for循环
-
for 循环更加复杂,但它是最常使用的循环形式。
-
begin 执行一次,然后进行迭代:每次检查 condition 后,执行 body 和 step
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/*
1.首先, 会先执行var count = 0;
2.根据条件执行代码
* count < 3
* alert(count) // 0 1 2
* count++
*/
for (var count = 0; count < 3; count++) {
alert(count)
}
</script>
</body>
</html>