" for "循环可以将代码块执行指定的次数。
For 流程图
JavaScript中 for 循环的流程图如下-
for 循环的语法是JavaScript,如下所示-
for (initialization; test condition; iteration statement) { Statement(s) to be executed if test condition is true}
请尝试以下示例,以了解 for 循环在JavaScript中的工作方式。
<html> <body> <script type = \"text/javascript\"> <!-- var count; document.write(\"Starting Loop\" + \"<br />\"); for(count = 0; count < 10; count++) { document.write(\"Current Count : \" + count ); document.write(\"<br />\"); } document.write(\"Loop stopped!\"); //--> </script> <p>Set the variable to different value and then try...</p> </body></html>
运行上面代码输出
Starting LoopCurrent Count : 0Current Count : 1Current Count : 2Current Count : 3Current Count : 4Current Count : 5Current Count : 6Current Count : 7Current Count : 8Current Count : 9Loop stopped! Set the variable to different value and then try...