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 trialImmanuel Jaeggi
5,164 PointsWhen to use conditional statements, while, do...while, and for loops.
Can someone explain the above by posting one simple example for each of the loops and conditional statements? It would be nice if your example is a real-world challenge, like asking a client to fill out a form for instance.
I understand how each one works individually, but when it comes to decide which one to implement when I actually code a website it gets tricky.
1 Answer
Adam N
70,280 PointsLoops are mostly all the same. They are used to repeat a block of code. Use for loops when you know how many times you want to repeat something, and while loops when you're not sure.
Let me know if this helps here