How to code 'for' loops

Code 'For' Loops

6
STEPS
TOOLS

This is the basic skeleton for a 'For' loop.

This is the basic skeleton for a 'For' loop.

The order of what should be in the parentheses is: for(/*beginning number; ending number; increment*/) { }

In this case, we will do: for (var i = 10; i >= 0; i-=1) { }

To ensure that the loop gets printed, we would type: "console.log(i)" between the braces.

And there you have it!  Beware: make sure you don't have infinite loops, otherwise it'll crash your browser!

And there you have it! Beware: make sure you don't have infinite loops, otherwise it'll crash your browser!

  • Wi-Fi
  • Computer