if (true)? i don't understand, if WHAT is true? is true a variable? shouldn't there be a "bool true = true" before? IM CONFUSE why does the block of code run when issuing an if (true)? how does it know true is true? shouldn't there be an assigned value to 'true'?
So take a step back real quick. Remember the variables episode to understand what is going on. You can think of a variable as a gift wrapped birthday present that stores something, in this case, it stores a Boolean value. Now booleans only have 2 values (in most languages) which is a true value, or false value, no matter what you name your variable, in the end it will either be true or false. & So with that, if you look at an if statement as a friend, you can give them your Boolean value gift wrapped, aka in a form of a variable, OR you can decide to not gift wrap it, & just give them their gift unwrapped & exposed, aka, explicitly writing true or false. Last note, when compile, true is always true, false is always false. Nothing changes when you wrap the value into a variable. If something is true, then run the code in the block, if not true, then of course, don't run the block. It's just how logic works.
Ok, so I got the jist of it, BUT, what if (pun intended), I wanted the FALSE value to actually do something? You've shown in the video that "if False" nothing will be output, what if I actually want it to output a value or a variable? 🤔
Well my guess is that The Boolean has to be either true or false, so that would mean that you have to make the Boolean be true when the output is false.
love your basic videos!
if (true)?
i don't understand, if WHAT is true? is true a variable? shouldn't there be a "bool true = true" before? IM CONFUSE
why does the block of code run when issuing an if (true)? how does it know true is true? shouldn't there be an assigned value to 'true'?
So take a step back real quick. Remember the variables episode to understand what is going on. You can think of a variable as a gift wrapped birthday present that stores something, in this case, it stores a Boolean value. Now booleans only have 2 values (in most languages) which is a true value, or false value, no matter what you name your variable, in the end it will either be true or false.
& So with that, if you look at an if statement as a friend, you can give them your Boolean value gift wrapped, aka in a form of a variable, OR you can decide to not gift wrap it, & just give them their gift unwrapped & exposed, aka, explicitly writing true or false.
Last note, when compile, true is always true, false is always false. Nothing changes when you wrap the value into a variable. If something is true, then run the code in the block, if not true, then of course, don't run the block. It's just how logic works.
@@Jabrils thanks man! this helped, especially the last paragraph
Ok, so I got the jist of it, BUT, what if (pun intended), I wanted the FALSE value to actually do something? You've shown in the video that "if False" nothing will be output, what if I actually want it to output a value or a variable? 🤔
That's a really good question, now I'm curious lol.
Well my guess is that The Boolean has to be either true or false, so that would mean that you have to make the Boolean be true when the output is false.
You would have to type an "Else" statement. (next video in the playlist) ☺
if(!true)
{//Do something}
else {//Do not do something}
! should be read as "if not" - in this case "so if not true, do this!"
do you need to have a boolean in the brackets?
No any statement can go into the brackets of an if statement 🙂
- Jabril
@@Jabrils ok!! Thank you! :D
You could write PASS