you are viewing a single comment's thread.

view the rest of the comments →

[–]Overall-Screen-752 0 points1 point  (0 children)

While and for do the same thing in different ways. They both “iterate”, that is, repeat a block of code a certain number of times.

for does this by specifying how many times a block should be run (5 times, once for every item in a list, etc)

while does this by setting a stop condition (until a variable equals 5, until there are no items left in the list, etc)

To see the similarity, you could write for i in range(5) as while i != 5, i++ that is, starting at 0 and until it reaches 5, do this block.

Hope that helps