# I don't understand how true and false works

 1 2 Like the title says I don't get how they work. I sort of understand them in while loops in that the while loop will only go on if it is true. I really didn't get how the print all links video answer works and the video didn't help. I also don't understand how if url: worked in that video. asked 05 Mar '12, 20:31 Ashley-2 18●1●2 accept rate: 0%

 11 It's actually easy (as everything, you already understand, of course, but this one really is): True and False are the only two values you can get from any logical expression, e.g.: Your name is Ashley. -> True It is the year 1912. -> False It is half past 2 AM here and I should really go to bed. -> True 1 == 1 -> True 1 + 1 == 3 -> False etc. Now, if statement takes an logical expression and allows its block to be executed only in case that expression evaluates to True: if :  The same applies to while loops. It will loop over and over again "while the condition (i.e. the logical expression) is evaluated as True" - that is why it is called "while"-loop. The same sentence in other words: While loop will stop right at the moment when the expression will evaluate as False - in case that expression will be always True, while will loop until the end of the Universe (or until the program crashes): while :  And the last thing is for if url:. It is just a shorthand notation for if url != "" (i.e. if url is not an empty string), given that url is a string. There is such shorthand for each data type: boolean: if variable != False number: if variable != 0 string: if variable != "" list: if variable != [] etc. answered 05 Mar '12, 20:45 Marek Bálint 4.7k●16●42●85 Very solid answer, Mareq. I just wanted to add how important the concept of boolean (binary, on/off, true/false) is in computer science. It is the foundation of all digital machines, including computers and is esential for understanding all programming languages. Fortunately, it is pretty easy to understand. (05 Mar '12, 21:01) Mark Brownstein Thanks a lot, that was a really clear and useful explanation. I think I get it now (06 Mar '12, 08:03) Ashley-2 The last bit is sometimes referred to "Truthiness" - For example, a nonzero number is Truthy. (06 Mar '12, 08:16) Thom Blake
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×15,276
×16