For further actions, you may consider blocking this person and/or reporting abuse
This community will be migrating to a dedicated subforem in the near future. We are excited to announce a new take on the CodeNewbie Community soon! Email support@forem.com if you have any questions.
The way I've always decided is that
forloops are for "known" lengths andwhileloops are for "unknown" lengths.To break this down further - if you have an array and need to loop over each element of the array, you can use
for (item of array). We know it's going to be a for loop because we want to hit each element 1 time over the course of our loop.If we wanted to add items to an array until the length of the array was 100 or more items, we could use
while (array.length < 100)- the big thing here is that we don't know how long our array will be when it starts.Does that clarify things?
It does, thanks so much!