The 'for' loop

Published on: April 26, 2017

Welcome to the twenty-third Easy JavaScript tutorial, part of EasyProgramming.net. In this tutorial, we will begin looking at loops by covering the "for" loop. 

If you haven't already, I would highly recommend that you watch my "for" loop tutorial in C++. It's a very old tutorial, but it's still relevant because the syntax of a for loop in C++ is the exact same as JavaScript. 

Loops in general allow you to execute the same piece of code over and over again. It may or may not have an ending and may or may not give you a different result (depending on your input). The "for" loop allows you to specify a beginning, an end, and the increment/decrement values. 

Syntax of the for loop:


  for (starting statement; ending condition/statement; increment/decrement value) {
    code block to be executed
  }

To fork the fiddle and follow along: https://jsfiddle.net/easyjs/tsg61x6v/

 

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!

Resources:

Comments: