The for loop is a structure used to execute one or more statements repeatedly as long as a condition is true. The for loop is particularly suitable if the required loop passes are already known in advance.
The loop usually uses a so-called counter variable. It usually contains a numeric value that controls the number of loop passes to be repeated by its increment or decrement.
for item in sequence: # code-block to be executed
for item in range(start, end, step): # code-block to be executed
The while loop is also used to execute one or more statements until a condition is no longer met. Unlike the for loop, the while loop does not use a counter variable. This would have to be explicitly incremented or decremented in the body of the loop.
If the condition does not return true on the first query, the while loop is not executed at all.
while condition: # code-block to be executed