- Javascript - Page Printing
- Javascript - Void Keyword
- Javascript - Dialog Boxes
- Javascript - Page Redirect
- Javascript - Cookies
- Javascript - Events
- Javascript - Functions
- Javascript - Loop Control
- Javascript - For...in
- Javascript - For Loop
- Javascript - While Loop
- Javascript - Switch Case
- Javascript - If...Else
- Javascript - Operators
- Javascript - Variables
- Javascript - Placement
- Javascript - Enabling
- Javascript - Syntax
- Javascript - Overview
- Javascript - Home
JavaScript Objects
- Javascript - HTML DOM
- Javascript - RegExp
- Javascript - Math
- Javascript - Date
- Javascript - Arrays
- Javascript - Strings
- Javascript - Boolean
- Javascript - Number
- Javascript - Objects
JavaScript Advanced
- Javascript - Browsers
- Javascript - Image Map
- Javascript - Debugging
- Javascript - Multimedia
- Javascript - Animation
- Javascript - Validations
- Javascript - Error Handling
JavaScript Useful Resources
- Javascript - Resources
- Javascript - Functions
- Javascript - Quick Guide
- Javascript - Questions And Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
JavaScript - For Loop
The for loop is the most compact form of looping. It includes the following three important parts −
The loop initiapzation where we initiapze our counter to a starting value. The initiapzation statement is executed before the loop begins.
The test statement which will test if a given condition is true or not. If the condition is true, then the code given inside the loop will be executed, otherwise the control will come out of the loop.
The iteration statement where you can increase or decrease your counter.
You can put all the three parts in a single pne separated by semicolons.
Flow Chart
The flow chart of a for loop in JavaScript would be as follows −
Syntax
The syntax of for loop is JavaScript is as follows −
for (initiapzation; test condition; iteration statement) { Statement(s) to be executed if test condition is true }
Example
Try the following example to learn how a for loop works in 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>
Output
Starting Loop Current Count : 0 Current Count : 1 Current Count : 2 Current Count : 3 Current Count : 4 Current Count : 5 Current Count : 6 Current Count : 7 Current Count : 8 Current Count : 9 Loop stopped! Set the variable to different value and then try...Advertisements