- Introduction of Loop Control
- Definition of Looping
- For Loop Introduction
- Syntax of For Loop
- Example of For Loop
- Display first ten numbers
- Display sum of first ten numbers
- Definition of Looping
The process of repeatedly performing tasks is known
as looping.
These statements are used to repeat the execution of
code for a fixed number of times or till some condition is satisfied. The
condition should be a Boolean condition.
- For Loop Introduction
The for loop combines initialization,
condition and the loop expression in a single statement. This loop executes
statements as long as the condition is true. As soon as condition becomes false
,control comes out of the loop.
- Syntax of For Loop
for(initialization;condition;incr/decr)
{
Loop statement/s;
}
1.initialization done and it is executed only once.
2.condition is checked,if false comes out loop,if
True execute loop statement.
Process continue upto condition is true.
- Example of For Loop
for(i=1;i<=10;i++)
{
document.write(i);
}
document.write("Exit"); //execute this statement when condition is false
Click Here For Video : For Loop
Click Here For Video:While Loop
- Example of For Loop
<!DOCTYPE html>
<head>
<title>Javascript Program</title>
</head>
<body>
<h1>For Example</h1>
<script type="text/javascript">
var i;
for(i=1;i<=10;i++)
{
document.write(i+"<br>"); //for
display to next line use <br> tag
}
</script>
</body></html>
Please Comment and Share. ConversionConversion EmoticonEmoticon