#Display
numbers from 1 to 10
i=1
while
i<=5:
print(i)
i+=1
"""output:
1
2
3
4
5
"""
while is a keyword, while suite are executed until while condition becomes false.
while is a keyword, while suite are executed until while condition becomes false.
While loop is useful to execute a group
of statements several times until condition becomes false.
Syntax:
while condition:
Statements
Related Video: https://www.youtube.com/watch?v=hFcv96-p4OE&feature=youtu.be
Difference between while and for loop:
Repeated code can be executed for every
element in a sequence in for loop. Where as in while loop: Repeated code can be
executed as long as condition is True.
#write
a program to prompt user to enter some name until enter Python
a=""
while a!="Python":
a=input("enter name:")
print("Thanks for
confirmation")
"""output:
enter name:python
enter name:Python
Thanks for confirmation
>>> """
Next Topic: Nested
loopsPrevious Topic: for loop
No comments:
Post a Comment