Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChristopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsHow Will I Remember All These Loops?
I have a very simple question. How am I supposed to remember all these loops that we have just learned? Maybe its the examples used, these guessing games, but right now they seem just too much for me to grasp properly.
8 Answers
Jacob Mishkin
23,118 PointsA good way to remember what type of loop you should use is to think about what you want your program/loop to do. Let's say you want to loop over something multiple times but are not sure how many times exactly, A while loop, and a do while loop does that exact thing. It loops until the is condition is false. the only difference between a do while and a while loop is, a do will execute the contents inside the loop once before the condition statement is evaluated.
Let's say you have an array, and you want to loop through it. This is where the for loop really comes in handy. You set the condition with an array is by using <, >, ect. plus .length. The loop will iterate thought the length of the array doing whatever code you want it to do.
And the for in loop. this is used when looping through properties in objects.
there are several other loops out there, but these 4 are a great base. the best way to remember what loop to use is first ask yourself why and what and I doing with the loop, and also practice, CODE EVERY DAY!.
So the general rule of thumb is, use while/do while loops, if you don't know how many times you need to iterate until a condition is false. A for loop is used for arrays, and a for in loop is used on properties in objects.
I hope this helps.
Micah Courey
20,168 PointsIt will take time to remember everything. The best way is to practice everyday by coding. When your watching these videos for the first time it is most important to understand the concepts and the logic behind them. Most programmers don't memorize every little thing but they understand how the different loops and arrays work so they know when to use them but they may need to reference the proper syntax in the online documentation and there is nothing wrong with that. Good luck with your studies!
Jesus Mendoza
23,289 PointsThat's why you study and practice, to learn and remember things, if you don't practice you forget things.
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsThis is the second time I am going through the loops, and everytime I can't just seem to remember which type of loop should be used to a particular situation. I guess with time it will come but for now whew!
Jesus Mendoza
23,289 PointsIt's ok bro we all feel that way when we are learning, with the time and experience you will know what to use and when to use it
A X
12,842 PointsJust practicing for me isn't enough if I don't understand the logic behind why we use different loops. Like I totally get that the do/while and while loops are similar except the do/while executes once...however, Dave never compared the do/while to the for, which I wish he would've...so I'm left wondering about the similarities/differences/when is best to use one vs. the other between those 2. No amount of practice will correct not understanding this, I have to look for answers first.
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsI am still a long way from understanding how JavaScript works, but now I have a good idea. Things like loops, functions, variables are taught as separate entities, but when one gets down to writing functional JavaScript, these entities are all grouped and interconnections made between the groups so that they produce an a single working output for the user, just like team work.
Mr Sri
9,200 PointsIf you are using an text editor, A good idea would be to save important blocks of code as snippets (clips in coda).
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsThanks Micah! Now I know I should not try to cram everything but just get a general idea how it works and of course there will be the online libraries for references. Now my anxiety has dissipated. :)
kevinardo
Treehouse Project ReviewerI have used flash cards to brain wash myself :) Have a look at this method mate, i can highly recommend it:
http://www.jackkinsella.ie/2011/12/05/janki-method.html
Good Luck with your studies, and NEVER GIVE UP :)
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsThanks Kevin, will try that!
Alfredo Gayou
7,051 Pointsalso almost all IDE have a way to help you with snippets, and as jacob said for is mainly used for arrays and for other uses they can be used indistinctively
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsChristopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsThanks Jacob this sure helps. I will make sure I remember it.