+ 1
Loops
Can using âwhile Falseâ ever ouput something? Can I get an example where using âwhile Falseâ outputs something?
3 RĂ©ponses
+ 1
No.
While False : means exit loop before starting...
edit:
Vivian Anoemuah
python has special addition to loops as else part:
while False:
print("never printed")
else:
print("this printed")
"""
(if none of times, loop body executed then else part will executed.. works for "for loop also"..)
"""
+ 1
While False will skip the code inside while.
You maybe need to add "not" for your condition (False one). For example :
x = 1
While not (x==2):
x+=1
print (x)
here you can see x==2 is False but with "not" you can go inside while.
+ 1
No, but...
while False:
...
else:
print("something")
Will print "something"