what's up everyone this video we are
gonna be talking about the single line
if statement and let me tell you what
this is probably the easiest video I got
so yeah prepare yourself but before I
enlighten you with tons of knowledge you
must first check out our sponsor Monday
com4 they have blessed me with such
sponsorship Monday comm is your visual
project management solution this is the
tool that allows you to see where every
task or project stands with a single
glance with a fully customizable
interface you can create the exact
workflow that you need for you and your
team to get stuff done Monday comm is
available on mobile and integrates well
with some of the most popular tools out
there so get your life in order by
giving it a try for free link in the
description now let's talk about this
complicated single line if statement
well let's say we have some variable and
what we're trying to do is we're trying
to an if statement so let's say we're
seeing if name is equal to Claire and
you might want to get this from user
input as I mentioned in almost every
video and then you know you can put the
curly braces and you can type out some
stuff here but if you're only doing one
individual thing it might be a lot
cleaner just to keep it all on one line
and just do it up here so for example we
can say console.writeline like so you
can see when we run this it says U is
lame and if we were to get a different
value for the input you see nothing
happens now there are a couple things
you need to watch out for on this and
that's what I'm gonna be talking about
now first thing is you can't do two
statements you can't go in here and say
something else this one will actually
execute every single time so basically
this one is the only one attached to the
conditional this is dangerous and as a
rule of thumb if the statement comes
directly after the if statement and it's
not on the next line inside of curly
braces then you can assume it's a single
line if statement and if you want to add
a statement like that then you need to
put the entire thing inside of curly
braces like so now these will both
execute if this is evaluated to true
this brings up another concern that is
if you have a single line if statement
but the actual statement is on the
second line it's very easy to forget
that it's a single line if statement
because it's structured as if it's a
multi
if statement but even now only this one
will get executed if this evaluates to
true so those are some of the things you
need to watch out for my rule of thumb
is if I have a single line if statement
I'll always get rid of this extra space
and put on the same line then I know if
I want to add stuff it just looks funny
and I need to remember to put in those
curly braces then I don't have any
issues awesome guys so that is a single
line if statement I know it was crazy
just make sure you watch this video a
couple hundred times to make sure you
got it down and then be sure to
subscribe because I got lots of more
useful videos coming up for you in just
a minute alright see you soon
[Music]