- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is for loop statement in JavaScript?
The 'for' loop is the most compact form of looping. It includes the following three important parts −
The loop initialization where we initialize our counter to a starting value. The initialization 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 line separated by semicolons.
Syntax
The syntax of for loop is JavaScript is as follows,
for(initialization;test condition;iteration statement){ Statement(s)to be executed if test condition is true }
Example
You can try to run the following example to learn how a for loop works in JavaScript −
<html> <body> <script> 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> </body> </html>
- Related Articles
- What is for...in loop statement in JavaScript?
- What is while loop statement in JavaScript?
- What is do...while loop statement in JavaScript?
- How to use for...in statement to loop through an Array in JavaScript?
- What is for each...in a statement in JavaScript?
- Can a for statement loop infinitely in java?
- Using else conditional statement with for loop in python
- what is enhanced for loop in Java?
- What is if statement in JavaScript?
- What is break statement in JavaScript?
- What is continue statement in JavaScript?
- Explain for. . .of loop JavaScript.
- Loop control statement in Java
- How to use else conditional statement with for loop in python?
- How to use PowerShell break statement with the For loop?

Advertisements