SHARE

An easier way to iterate through a loop is via the for loop, which we’ll talk about in this JavaScript tutorial. A for loop does exactly the same thing as a while loop, but it has the advantage of organizing it’s components more locally and neater.

As always, if you have any questions, fire ahead with them below :).

SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

========== JavaScript for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9i9Ae2D9Ee1RvylH38dKuET

========== CSS for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9gQeDH6xYhmO-db2mhoTSrT

========== HTML for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9ibZ2TSBaGGNrgh4ZgYE6Cc

========== The Net Ninja ============

For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk

========== Social Links ==========

Twitter – @TheNetNinja – https://twitter.com/thenetninjauk

9 COMMENTS

  1. I have a question that has been bugging me for some time now. If I wanted to use the variable i inside the loop, to let's say push an 'input to the alert' into an array of objects, how would I go about that?

  2. Great tutorials lads. Nothing better than showing 'actual examples' like looping through links, then just going over the fundamentals.

  3. I am using brackets and typed in the code, verbatim, with the following errors  JSLint (6)3'i' was used before it was defined.for (i = 1; i < links.length; i++) {3Unexpected '++'.for (i = 1; i < links.length; i++) {3Unexpected '(space)'.for (i = 1; i < links.length; i++) {5'console' was used before it was defined.console.log("this is link number" + i);9Expected 'document' at column 1, not column 3.document.write("all liks are looped");Help?

  4. You do need 'var' keyword for 'for' loop variable, otherwise you create a global variable which remains while page lives. Let alone cases when you recursively call a function containing 'for' loop. And if you use ECMA6 then 'let' variable is even better for 'for' loop.

  5. hi there, great videos, really learning alot from your playlist of this series. Just a quick question, you dont seem to be using var to declare the new variables within the for loops, the code still seems to work, so just wanted to confirm, is var not required within the for loop or is it good practice to use it. e.g. you did:

    – for (age = 5; age < 10; age++) however should i be doing:
    – for (var age = 5; age < 10; age++) instead.

    Thanks again.

  6. Nice video. One thing I would like to point out is that, even though u said and perhaps assume that for and while loops are used for the same purpose, they are quite different in nature. e.g. a for loop is used when u are more sure of the no. of steps or conditions. While loop is more flexible and u can use a while loop as long as a condition is met and u are unsure about the steps to reach that condition. Also FOR loop requires a variable and variable update. While loop can work with existing variable and even here is more flexible.

  7. When i attempted this tutorial "Your age is less than 10 " was printed out to the screen 5 times and then "You are now over 10"

LEAVE A REPLY

Please enter your comment!
Please enter your name here