JS For Loop Statement
JavaScript For Loop Statement
JavaScript For Loop Statement
-
For Loop statement – is a loop statement that evaluates the expression.
If it meets the condition of initialization then increment the value of initialization and repeat execution steps until no longer meets execution.
Syntax:
for (initialization; condition; incrementation){
If condition is true then execute the statement
}
|
<script type="text/javascript">
<!--
var i;
document.write("Start Loop" + "<br />");
for(i = 0; i < 5; i++){
document.write("Variable i : " + i + "<br />");
}
document.write("Stop Loop");
//-->
</script>
|
The result:
Start Loop Variable i : 0 Variable i : 1 Variable i : 2 Variable i : 3 Variable i : 4 Stop Loop |