Python For Loop Condition Definition:
When there is a need to loop through a set of things such as a list of words (or) the lines
in a file. In this case we can construct a definite loop using a for statement.
The key difference between ‘While’ condition and ‘For Loop’:
while statement is an indefinite loop because it simply loops until some condition becomes False.
for loop is looping through a known set of items so it runs through as many iterations as there are items in the set.
Example 1:
friends = ["John", "Kevin", "Karen"]
for friend in friends:
===>print(friend)
Result:
John
Kevin
Karen
Example 2:
for index in range(10):
===>print(index)
Result:
0
1
2
3
4
5
6
7
8
9
Example 3:
for index in range(5, 10):
===>print(index)
Result:
5
6
7
8
9
Example 4:
friends = ["John", "Kevin", "Karen"]
for index in range(len(friends)):
===>print(friends[index])
Result:
John
Kevin
Karen