while else python
#there are 2 ways to make a while loop in python
#first way -
while True:
(#what ever you want in the loop)
#second way -
while 1:
(#what ever you want in the loop)
4
5
while <Condition>:
<code>
#example
i = 10
while i == 10:
print("Hello World!")
Thank you!
5
0
3.5
6
target = 100
current = 0
while current != target:
current += 1
print(current)
#The while loop repeats the indented code while its condition is true
#(current IS NOT equal to target).
else:
print("Target Reached!")
#When the while loop condition is no longer true (current IS equal to target),
#the indented code under else: is ran.
Thank you!
6
0
Are there any code examples left?
New code examples in category Python