+ 1

Loops

Can using ‘while False’ ever ouput something? Can I get an example where using ‘while False’ outputs something?

6th Jan 2022, 12:15 PM
Vivian Anoemuah
Vivian Anoemuah - avatar
3 Respostas
+ 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"..) """
6th Jan 2022, 12:20 PM
Jayakrishna 🇮🇳
+ 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.
6th Jan 2022, 12:43 PM
YoPycode
+ 1
No, but... while False: ... else: print("something") Will print "something"
6th Jan 2022, 1:09 PM
Angelo
Angelo - avatar