Learn JavaScript
  • Introduction
  • Basics
    • Comments
    • Variables
    • Types
    • Equality
  • Numbers
    • Creation
    • Basic Operators
    • Advanced Operators
  • Strings
    • Creation
    • Concatenation
    • Length
  • Conditional Logic
    • If
    • Else
    • Comparators
    • Concatenate
  • Arrays
    • Indices
    • Length
  • Loops
    • For
    • While
    • Do...While
  • Functions
    • Declare
    • Higher order
  • Objects
    • Creation
    • Properties
    • Mutable
    • Reference
    • Prototype
    • Delete
    • Enumeration
    • Global footprint
Powered by GitBook
On this page
  1. Loops

For

The easiest form of a loop is the for statement. This one has a syntax that is similar to an if statement, but with more options:

for (condition; end condition; change) {
    // do it, do it now
}

Lets for example see how to execute the same code ten-times using a for loop:

for (var i = 0; i < 10; i = i + 1) {
  // do this code ten-times
}

Note: i = i + 1 can be written i++.

PreviousLoopsNextWhile

Last updated 4 years ago