0
Clear my head,What's the difference between "for loop" and "while loop" in python?
2 Answers
+ 7
The for loop executes a piece of code for every item in a container, for example a list, a dictionary, a tuple, a predefined range of numbers...
In pseudocode: for fruit in fruitbasket, for word in vocabularyBook, for letter in word, for number in telephoneNumbers...
So all items of an iterable are iterated over.
A while loop runs as long as a condition is true.
for example:
while x>5:
# And here, you have some code
# You change x in the process
# and as soon as x is not >5
# the loop stops.
0
Right. A for loop iterates through an iterable (such as a list or an array) And a while loop loops as long as the condition is true