+ 2

How to stop while loop function in python?

8th Jul 2020, 1:20 AM
LOKESH CHAUHAN
LOKESH CHAUHAN - avatar
2 Answers
+ 4
I assume that you are asking about breaking out of a loop, use break then Eg: https://code.sololearn.com/cNJ1pgorRryB/?ref=app
8th Jul 2020, 1:27 AM
A C K
A C K - avatar
+ 2
x = 5 while x > 0 x = x - 1 After counting down 5 4 3 2 1 the loop stops. Additionally you could say: while x > 0 if x == 2 break And the code will exit the loop early
9th Jul 2020, 1:32 AM
Kevin Schow
Kevin Schow - avatar