What is the actual difference between a for loop and a while loop?

Posted by Sofiatheneophyte@reddit | learnprogramming | View on Reddit | 41 comments

please don't judge me, I'm a complete beginner. I've been googling this for a while and I think I kind of get it but I'm not sure.

from what I understand a for loop is when you already know how many times you want to repeat something, and a while loop is when you keep going until a condition is false. But then I tried writing both and got the same result which confused me a lot:

```python

for i in range(5):

print(i)

i = 0

while i < 5:

print(i)

i += 1

```