The way I've always decided is that for loops are for "known" lengths and while loops 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.
for (item of array)
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.
while (array.length < 100)
Does that clarify things?
It does, thanks so much!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
For further actions, you may consider blocking this person and/or reporting abuse