

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to prevent loops going into infinite mode in Python?
Loops formed with for statement in Python traverse one item at a time in a collection. Hence there is less likelihood of for loop becoming infinite.
The while loop however needs to be controlled by making some provision inside the body of the loop to drive the condition mentioned in the beginning to false.This is usually done by keeping count of iterations
x=0 while x<5: x=x+1 print (x)
Loop repetition can also be controlled by using break to take an early exit from the iterations
while True: stmt1 stmt2 if expr==True: break stmt3 ..
- Related Questions & Answers
- How do I prevent an iOS device from going to sleep mode?
- How do I prevent an Android device from going to sleep mode?
- How to handle Infinite loops in Postman Workflow?
- How to prevent going back to the previous activity in Android?
- Index into an Infinite String in Python
- How to use nested loops in Python?
- How to stop an infinite loop safely in Python?
- How to make loops run faster using Python?
- How to use else statement with Loops in Python?
- In ABAP, How to select all the data into my internal table using loops?
- How to use single statement suite with Loops in Python?
- How can I represent an infinite number in Python?
- How do I run two python loops concurrently?
- How to use multiple for and while loops together in Python?
- Loops in Java
Advertisements