+ 1

How do one iterates to until a certain condition is fulfilled and then know exactly how many times the code underwent the loop?

31st May 2022, 12:14 PM
Awe Akinwumi Jethro
5 Answers
+ 3
You could create a variable and increase it it by one every iteration.
31st May 2022, 12:19 PM
Stefanoo
Stefanoo - avatar
+ 1
A more pythonic way is to use enumerate.
3rd Jun 2022, 9:38 PM
Louis
Louis - avatar
0
Hi! You use a for loop to iterate through a collection, and a if statment in the loops body. When the if condition is true, you use ā€˜break’ to break the loop. Read more about it in the Python courses on SoloLearn.
31st May 2022, 12:30 PM
Per Bratthammar
Per Bratthammar - avatar
0
count=0 for i in range(5): count+=1
31st May 2022, 5:08 PM
João Gonçalves