There are still perfectly valid use cases for the for loop. For example, if you want to break out of the loop early there’s the break keyword.
Or if you want to not iterate over the items of an array, but rather just repeat something a certain number of times, a for loop is useful there too.
A for loop also lets you have more complex logic for when you should continue looping. Remember that for loops are not only used for iterating over an array.
Some comments have been hidden by the post's author - find out more
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.