# Some important questions about the while loop in Python to practice

• While loop execute a set a statement as long as test statement is true.
• A relevant variable has to be declared at the beginning of the loop

Until a specified condition is met, a block of statements will be periodically executed in a Python while loop. And the line in the programme that follows the loop is run when the condition changes to false.

The while loop is an example of an infinite loop. When a loop is iterated indefinitely, the number of times the loop is run isn’t explicitly stated beforehand.

### Example 1: Python While Loop

# while loop
count = 0
while (count < 3):
count = count + 1

output

### Write a program to print table of a number entered from the user.

a=int(input(“enter number”))
i=1
while i<10:
print(a,”*”,i,”=”,a*i)
i=i+1

### Create a programme that uses a while loop to determine whether an integer is prime or not.

num1 = int(input(“Enter any number : “))
k=0
if num1 == 0 or num1 == 1:
print(“Not a prime number “)
else:
i = 2
while(i<num1):
if num1 % i == 0:
k = k+1
i = i+1
if k == 0 :
print( num1,”is prime number”)
else:
print(num1, “is not prime number”)
output
Enter any number : 67
67 is prime number

Scroll to Top