Questions

Is While Loop Infinite Python?

A while loop is usually not infinite in Python. It only executes a code block repeatedly as long as the given condition is satisfied. The right-hand side of the expression gets evaluated first, and then the value is assigned to a variable. If the given loop condition is False, the loop is terminated or a different set of code is executed. 

For example:

                    

p = int(input('Enter your age: '))
while p < 19 or p > 60:
    print('You are too young or too old to ride!') 
else:
    print('Welcome, you are of the right age!')

Program execution:

                    

Enter your age: 45
Welcome, you are of the right age!

Related Questions

Related Topics

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

avatar
  Subscribe  
Notify of

Customize your course in 30 seconds

Which class are you in?
No thanks.