python while loop :
- The while loop is also known an precondition loop.
- While loop allows the part of code to be executed when the given condition is true.
- while loop is mostly used where the number of iteration is not known in advance.
Syntax :
While Expression(condition):
Statements.......
Example :
>>>i =1
>>> while i<=10:
print(i)
i = i+1
1
2
3
4
5
6
7
8
9
10
>>>
printing the table of the given number using While loop :
>>> i = 1
>>> n = int(input("Enter number :"))
Enter number :10
>>> while i<=10:
print(n * i)
i = i+1
10
20
30
40
50
60
70
80
90
100
>>>
i=1
ReplyDeletewhile i<=10:
if i%2==0:
print(i)
i=i+1