Work with loops JavaScript


show more Learn how to repeat your JavaScript code with loops. Simon Allardice shows how to write while and for loops, including specifying the number of iterations, checking conditions, incrementing values, and breaking loops. show less
please wait ...

Working with loops

Very quickly we will find ourselves writing code that we want to have happen multiple times. Whether that's grabbing every paragraph in a page so we can change the background color of it, hiding everything in a menuing system, we will realize there's code we want repeated. Well, rather than write it out multiple times, I'd rather write it once and be able to say, "Repeat this five times," or "Repeat this 5,000 times," or "Just keep on repeating till I tell you otherwise," perhaps go through every single form field on the web page or process every link on a web page in some way, and this is what we do when we are creating loops.

You will also hear this referred to as iteration. The main issue with any loop is not when to loop--looping is easy--it's when to stop. If we need to loop 200 times, who is keeping track? If we need to loop until we are told to stop, where is the code to figure out how to stop? But let's first figure out the most b...

Working with loops
Video duration: 8m 1s 5h 31m Beginner

Viewers:

Learn how to repeat your JavaScript code with loops. Simon Allardice shows how to write while and for loops, including specifying the number of iterations, checking conditions, incrementing values, and breaking loops.

Subjects:
Developer Web
Software:
JavaScript
Author:
please wait ...