0

Why does my python loop only execute once?

1st Sep 2024, 10:00 AM
onifade David
onifade David - avatar
7 Réponses
+ 3
If you have a loop in your code ... and it executes once successfully (without causing an exception) ... and you were expecting it to run more than once ... and there is no other exit within the loop, such as a break statement then the loop condition must be wrong or else a factor that updates the condition is wrong. If it is a while loop, then check the conditional. A while loop executes while the conditional is true. If it is a for loop, then check the start value, the end value, and the step increment.
1st Sep 2024, 2:29 PM
Brian
Brian - avatar
+ 3
onifade David , can you please link your code here?
1st Sep 2024, 3:30 PM
Lothar
Lothar - avatar
+ 2
there is no loop...
1st Sep 2024, 10:03 AM
Lisa
Lisa - avatar
+ 2
Example please
1st Sep 2024, 1:47 PM
Bob Balinski
0
Probably because the condition for your loop jas been meet
1st Sep 2024, 4:08 PM
Oluwatumininu Owolabi
Oluwatumininu Owolabi - avatar
0
If you are using a for loop, you have to insert a value in the brackets; For example, for i in range(5): print("Hello World.") But if you want it to loop an infinite number of times, use a while loop.
2nd Sep 2024, 12:13 PM
Jedix
Jedix - avatar
0
Can you send your code
2nd Sep 2024, 6:14 PM
Fateme Biglari
Fateme Biglari - avatar