You learnt that both the for loop as well as the while loop are interconvertible, but is that always true that both the loops can be changed into each other? Let’s see about that in detail in the next video.
It can be understood better by understanding when to use a for loop and when to use a while loop. A for loop is to be used when you want to perform steps for a particular number of times. So in cases like looping through 0 - 1000 to print all the numbers, for loop is a better choice although as you’ve seen, the while loop can also be used in this scenario.
On the other hand, a while loop performs steps while a condition remains true. This is why while is useful for cases where you aren’t sure for exactly how many steps will the loop run. So for reading the lines in a file, where you do not know the number of lines beforehand, using while loop is a better idea.