We can create infinite loops in Python via the while statement. In a loop, the variable is evaluated and repeatedly updated (while the given condition is True). We can create an infinite loop in Python if we set the condition in a way that it always evaluates to True.
For example:
p = int(input('Enter a number: '))
while p != 0:
for q in range (1, p):
print (q)
q+=1
p = int(input('Enter a number: '))
Program execution:
Enter a number: 9
1
2
3
4
5
6
7
8
Enter a number: 4
1
2
3
Enter a number: 6
1
2
3
4
5
Enter a number:
Related Questions
- How do you write first code in Python?
- How do you write a matrix in python?
- What are Python namespaces why are they used?
- How do I write a Python script?
- Is while loop infinite Python?
- How do you write a 3×3 matrix in python?
- How do you create a namespace in Python?
- How do you make an infinite while loop?
- How do you create a matrix list in Python?
- What is datatype in Python?
- Which software is best for Python programming?
- Why is my FOR LOOP infinite Python?
- Which is not valid namespace in Python?
- How many datatypes are there in Python?
Related Topics
- Python Programming
- 9 Best Python IDEs and Code Editors
- Python Input-Output (I/O) Using input() and print() Function
- List of Keywords in Python Programming
- Python Keywords and Identifiers (Variable names)
- Python List Comprehension (With Examples)
- Python Looping Techniques
- Python Main Function
- Python Matrix and Introduction to NumPy
- Python Namespace and Scope of a Variable
- Python PIP
- Python Statement, Indentation, and Comments
- Python Type Conversion and Type Casting (With Examples)
- Python Variables, Constants, and Literals
- Python Data Types
Leave a Reply