- JavaScript Basics
- JavaScript Home
- JavaScript Syntax
- JavaScript Placements
- JavaScript Output
- JavaScript Statements
- JavaScript Keywords
- JavaScript Comments
- JavaScript Variables
- JavaScript var
- JavaScript let
- JavaScript const
- JavaScript var Vs let Vs const
- JavaScript Operators
- JavaScript Comparison/Logical
- JavaScript Data Types
- JS Conditional Statements
- JavaScript Conditional Statement
- JavaScript if Statement
- JavaScript if-else Statement
- JavaScript switch Statement
- JavaScript Loops
- JavaScript for Loop
- JavaScript while Loop
- JavaScript do-while Loop
- JavaScript Break Continue
- JavaScript Popup Boxes
- JavaScript Dialog Box
- JavaScript alert Box
- JavaScript confirm Box
- JavaScript prompt Box
- JavaScript Functions
- JavaScript Functions
- JS Function with Parameter
- JavaScript Return Statement
- JavaScript Variable Scope
- JavaScript setTimeout() Method
- JavaScript setInterval() Method
- JavaScript Events
- JavaScript Events
- JavaScript onclick Event
- JavaScript onload Event
- JavaScript Mouse Events
- JavaScript onreset Event
- JavaScript onsubmit Event
- JavaScript Objects
- JavaScript Objects
- JavaScript Number Object
- JavaScript Array Object
- JavaScript String Object
- JavaScript Boolean Object
- JavaScript Math Object
- JavaScript RegExp Object
- JavaScript Date Object
- JavaScript Browser Objects
- JavaScript Browser Objects
- JavaScript Window Object
- JavaScript Navigator Object
- JavaScript History Object
- JavaScript Screen Object
- JavaScript Location Object
- JavaScript Document Object
- JS Document Object Collection
- JS Document Object Properties
- JS Document Object Methods
- JS Document Object with Forms
- JavaScript DOM
- JavaScript DOM
- JavaScript DOM Nodes
- JavaScript DOM Levels
- JavaScript DOM Interfaces
- JavaScript Cookies
- JavaScript Cookies
- JavaScript Create/Delete Cookies
- JavaScript Advance
- JavaScript Regular Expression
- JavaScript Page Redirection
- JavaScript Form Validation
- JavaScript Validations
- JavaScript Error Handling
- JavaScript Exception Handling
- JavaScript try-catch throw finally
- JavaScript onerror Event
- JavaScript Multimedia
- JavaScript Animation
- JavaScript Image Map
- JavaScript Debugging
- JavaScript Browser Detection
- JavaScript Security
- JavaScript Misc
- JavaScript innerHTML
- JavaScript getElementById()
- JS getElementsByClassName()
- JS getElementsByName()
- JS getElementsByTagName()
- JavaScript querySelector()
- JavaScript querySelectorAll()
- JavaScript document.write()
- JavaScript console.log()
- JavaScript Programs
- JavaScript Programs
- JavaScript Test
- JavaScript Online Test
- Give Online Test
- All Test List
JavaScript for Loop
The for loop in JavaScript is used to execute a block of code or group of statements multiple times based on the given/particular condition.
Here is the general form to use for loop in JavaScript:
for(initialization; condition-checker; incrementation) { // block of code, to be executed here }
Here is the explanation:
- initialization - This part is used to initialize the loop variable. This part is executed first, after the execution, loop control never executes this part. After executing the initialization part, loop control transfers to the condition-checker part
- condition-checker - This part is executed to check whether the condition evaluates to true or false. If true, then the loop control transfers to the body of the loop to execute the given block of code, otherwise if false, then the loop exits. Every time loop control transfers to the condition-checker part after incrementation part, except at the first time. At first time, loop control transfers to condition-checker part after initialization part
- incrementation - This part is executed every time after running the block of code present inside the loop. This part is is to increment or decrement the loop variable
JavaScript for Loop Example
Here is an example illustrates how to use for loop in JavaScript:
<!DOCTYPE HTML> <html> <head> <title>JavaScript for Loop</title> </head> <body> <h3>JavaScript for Loop Example</h3> <script type="text/javascript"> var num = 2; document.write("Printing the table of " + num + "<br/>"); var i; for(i=1; i<=10; i++) { document.write(num*i + "<br/>"); } document.write("Done!"); </script> </body> </html>
Here is the sample output of the above for loop example in JavaScript:

« Previous Tutorial Next Tutorial »