WEBVTT
Kind: captions
Language: en

00:00:00.860 --> 00:00:14.040 align:start position:19%
programming tutorials are back hey I
know it's been a while but we are back

00:00:11.490 --> 00:00:17.940 align:start position:19%
in full force with our c-sharp
programming tutorials the last tutorial

00:00:15.870 --> 00:00:21.570 align:start position:19%
we focused on outputting text to the
console now we're going to be taking a

00:00:19.529 --> 00:00:26.550 align:start position:19%
look at getting text in from the console
so user input see your writing program -

00:00:24.210 --> 00:00:30.689 align:start position:19%
to collect someone's name or their age
this is how we would do that we're also

00:00:29.010 --> 00:00:35.010 align:start position:19%
going to be going over its statements
now if statements are just ways of

00:00:33.000 --> 00:00:39.899 align:start position:19%
checking if things are true or if things
are false so say if you're making a

00:00:37.260 --> 00:00:45.239 align:start position:19%
video game you use an if statement you'd
say if the players health is you know

00:00:42.390 --> 00:00:49.710 align:start position:19%
below zero then they would be dead it's
very simple stuff and we're drinking

00:00:47.940 --> 00:00:53.789 align:start position:19%
water because monster is expensive as
[&nbsp;__&nbsp;] in Hawaii so we're just going to

00:00:51.930 --> 00:01:00.120 align:start position:19%
come into our blank project and start
with capturing some user inputs so I'm

00:00:55.590 --> 00:01:06.810 align:start position:19%
going to do consult dot read line
instead of write line and end that off

00:01:04.260 --> 00:01:11.909 align:start position:19%
with a semicolon of course now this is
going to pause execution and it's going

00:01:09.420 --> 00:01:16.320 align:start position:19%
to wait for user input now once we get
that user input we're not storing it

00:01:13.979 --> 00:01:21.090 align:start position:19%
anywhere so we need to put it in a
variable like we talked about from

00:01:17.640 --> 00:01:24.920 align:start position:19%
laughs from the last tutorial so the
type of data that's returned from the

00:01:23.070 --> 00:01:31.829 align:start position:19%
console dot read line function is a
string so I have to say string and we

00:01:27.900 --> 00:01:35.490 align:start position:19%
can call that input is equal to what's
returned from that and there you go so

00:01:33.810 --> 00:01:41.729 align:start position:19%
now we're storing whatever the user
inputs from the console into the string

00:01:38.280 --> 00:01:51.450 align:start position:19%
or into the input variable now let's
just use that input variable and do a

00:01:44.810 --> 00:02:00.509 align:start position:19%
console console dot write line and we
can output that input so now when we run

00:01:56.159 --> 00:02:05.640 align:start position:19%
the program it's going to pause and we
can say something like meme and then

00:02:02.790 --> 00:02:10.920 align:start position:19%
it'll output me that's you know boring a
[&nbsp;__&nbsp;] right so how do we spice things up

00:02:08.399 --> 00:02:12.530 align:start position:19%
well first off let's prompt the user for
what there

00:02:11.300 --> 00:02:16.250 align:start position:19%
and putting they have no idea what
they're inputting right now and we

00:02:14.720 --> 00:02:20.240 align:start position:19%
already learned this we can do console
dot write and that's just a little

00:02:18.860 --> 00:02:24.110 align:start position:19%
different from right line right line
we'll go to the next line and write will

00:02:22.310 --> 00:02:30.920 align:start position:19%
just keep things on the same line you
can see what I mean in a second we can

00:02:26.060 --> 00:02:35.660 align:start position:19%
problem for say your name all right now
and then a semicolon and ctrl f5 to run

00:02:33.710 --> 00:02:41.540 align:start position:19%
so here's what it looks like when it
runs it's prompting us for our name we

00:02:37.850 --> 00:02:45.830 align:start position:19%
can put our name and it outputs you know
our name Harambee but michael that's

00:02:44.060 --> 00:02:50.030 align:start position:19%
still boring a [&nbsp;__&nbsp;] so let's poke around
a bit with our output we're going to do

00:02:48.080 --> 00:02:53.960 align:start position:19%
something called string concatenation
and I know that's a pretty long sounding

00:02:52.040 --> 00:02:59.000 align:start position:19%
complicated word but it's really not
it's just taking two strings and mashing

00:02:57.050 --> 00:03:03.380 align:start position:19%
them together so we can take our input
which is being outputted right here and

00:03:00.920 --> 00:03:10.670 align:start position:19%
we can concatenate it with something we
can say and say like name and the way we

00:03:08.000 --> 00:03:15.260 align:start position:19%
concatenate things are with a plus sign
and make sure to leave that space or

00:03:13.250 --> 00:03:18.650 align:start position:19%
else these are going to the input and
this string the name are going to be

00:03:17.720 --> 00:03:24.310 align:start position:19%
right next to each other so we're just
going to leave a little space there and

00:03:19.850 --> 00:03:28.790 align:start position:19%
if we run this and I put in my name
cool name of Michael you know I already

00:03:26.900 --> 00:03:33.220 align:start position:19%
knew my name was Michael but you know
we're making progress so we can expand

00:03:31.340 --> 00:03:39.440 align:start position:19%
upon some of the stuff we learned here
instead of just taking in someone's name

00:03:35.750 --> 00:03:42.590 align:start position:19%
how about we take in their age and we
have to save this to a different

00:03:40.459 --> 00:03:46.790 align:start position:19%
variable we can call age just to keep
with good naming conventions we don't

00:03:44.330 --> 00:03:51.680 align:start position:19%
want one called input and another
variable called age so let's change this

00:03:48.620 --> 00:03:55.940 align:start position:19%
one to name and I'm just going to put a
line for clarity here and you know

00:03:54.380 --> 00:04:02.180 align:start position:19%
obviously the variable input doesn't
exist anymore so we're just going to

00:03:57.620 --> 00:04:05.900 align:start position:19%
have to change that to name and I have
always spice things up with our string

00:04:04.220 --> 00:04:13.250 align:start position:19%
or concatenate at two let's let's make
it a little nicer so my name is and then

00:04:10.670 --> 00:04:21.620 align:start position:19%
it will output whatever name we input
here and let's concatenate another

00:04:15.560 --> 00:04:26.069 align:start position:19%
string and I am and then we can
concatenate our age

00:04:23.550 --> 00:04:33.650 align:start position:19%
so if we want run the program and we
input our name Michael and we input our

00:04:29.250 --> 00:04:41.090 align:start position:19%
age you almost got me [&nbsp;__&nbsp;]
we'll say 12 to 34 my name is Michael

00:04:38.729 --> 00:04:48.660 align:start position:19%
and I am 12 to 34 you'll see here that
there is a no space between m and 12 234

00:04:46.349 --> 00:04:53.639 align:start position:19%
that's because we forgot a space there
and now when we run it it will have a

00:04:51.690 --> 00:04:57.240 align:start position:19%
space and look real nice I'll put a
little aside about software development

00:04:54.919 --> 00:05:00.659 align:start position:19%
always assume that the end user is a
complete [&nbsp;__&nbsp;] because more often than

00:04:59.639 --> 00:05:08.340 align:start position:19%
not they are they're going to try and
break your stuff they're going to not

00:05:01.830 --> 00:05:11.610 align:start position:19%
use it how you plan to have it used so
they're going to go in and do stuff that

00:05:09.960 --> 00:05:15.270 align:start position:19%
you didn't want this is my name is
Harambee and I am your expecting them

00:05:13.380 --> 00:05:20.190 align:start position:19%
put their age but they put in a string
instead you know I am alive so you know

00:05:18.300 --> 00:05:23.759 align:start position:19%
always be on the lookout for that okay
so now we have a better understanding of

00:05:21.630 --> 00:05:28.409 align:start position:19%
taking in user input so now let's just
delete all of that and start learning

00:05:26.580 --> 00:05:32.639 align:start position:19%
about if statements I know it's kind of
a weird transition but we're going to

00:05:30.659 --> 00:05:36.030 align:start position:19%
put the two together and make something
sort of useful at the end of this

00:05:34.229 --> 00:05:40.020 align:start position:19%
tutorial so just trust me on that
so if statements are an incredibly

00:05:38.370 --> 00:05:43.979 align:start position:19%
important part when working with any
programming language yet they're pretty

00:05:42.630 --> 00:05:50.070 align:start position:19%
simple of their foundation so let me
show you how one looks if Wow so those

00:05:47.099 --> 00:05:54.090 align:start position:19%
pretty complicated so if the condition
that we give in these parentheses is

00:05:51.509 --> 00:05:58.530 align:start position:19%
true then the code between these
brackets will execute so let's give it

00:05:56.550 --> 00:06:04.949 align:start position:19%
something to check we'll just create a
variable simple variable we'll call it

00:06:01.590 --> 00:06:09.389 align:start position:19%
int X as equal to 10 so we have an
integer X is equal to the value 10 and

00:06:07.500 --> 00:06:17.069 align:start position:19%
inside of this if statement we're going
to say if the integer X is equal to 10

00:06:14.460 --> 00:06:28.349 align:start position:19%
then we'll execute the code in here
which we can make console dot write line

00:06:19.979 --> 00:06:33.750 align:start position:19%
and X is 10 right so if X is equal to 10
right here then we're going to execute

00:06:30.900 --> 00:06:36.789 align:start position:19%
this code console dot write line access
10

00:06:35.050 --> 00:06:41.650 align:start position:19%
so something you may have noticed is
that inside of here we have two equal

00:06:39.039 --> 00:06:45.159 align:start position:19%
signs instead of one it's important to
understand that these are two kind of

00:06:43.300 --> 00:06:51.009 align:start position:19%
completely different things the double
equal sign is to denote that we're

00:06:46.990 --> 00:06:56.740 align:start position:19%
evaluating this so if X is equivalent
it's known as the equivalence operator

00:06:53.259 --> 00:07:01.720 align:start position:19%
if X is equivalent to 10 then we're
going to execute you know all the code

00:06:58.659 --> 00:07:04.810 align:start position:19%
inside this bracket up here when it's
just a single equals it's known as the

00:07:03.340 --> 00:07:08.919 align:start position:19%
assignment operator because we're
assigning the value 10 to the variable X

00:07:06.789 --> 00:07:15.159 align:start position:19%
they're totally different things so now
if we execute this it outputs that X is

00:07:12.130 --> 00:07:19.419 align:start position:19%
10 so if what happens if we change X to
something that is not 10 well then well

00:07:18.130 --> 00:07:22.449 align:start position:19%
I'll just run it and you'll see nothing
happens that's because we go in here it

00:07:21.970 --> 00:07:26.469 align:start position:19%
checks
oh if X is equal equivalent to 10 then

00:07:25.360 --> 00:07:30.729 align:start position:19%
we're going to execute this stuff
obviously it isn't so we just skip right

00:07:28.419 --> 00:07:34.389 align:start position:19%
by it and the program ends all right so
that's all well and good but there are a

00:07:32.740 --> 00:07:38.800 align:start position:19%
few more logical operators I want to
cover I don't do that pretty fast I'll

00:07:36.400 --> 00:07:43.750 align:start position:19%
go back in and explain each one in more
detail so where do you know what this

00:07:40.690 --> 00:07:47.110 align:start position:19%
one does this is for nonequivalence this
one is you know you recognize this this

00:07:45.669 --> 00:07:51.789 align:start position:19%
is for greater than this is for less
than this is for greater than or equal

00:07:49.870 --> 00:07:56.259 align:start position:19%
to and this one is for less than or
equal to and these we won't talk about

00:07:54.219 --> 00:08:00.039 align:start position:19%
these today so let's have a look at the
non equivalent operator so if we come in

00:07:58.509 --> 00:08:04.569 align:start position:19%
here and we change our equivalent
operator to the non equivalence operator

00:08:01.870 --> 00:08:09.669 align:start position:19%
then this is saying okay so if our X
variable is not equal to 10 so if it's

00:08:07.509 --> 00:08:15.729 align:start position:19%
equal to any other number in the
universe well you know that and can hold

00:08:12.219 --> 00:08:20.289 align:start position:19%
then we'll execute the stuff inside of
here and how it would just say execute

00:08:18.400 --> 00:08:26.110 align:start position:19%
so we don't have to keep changing that
every single time and we run that and

00:08:22.810 --> 00:08:32.310 align:start position:19%
because X is not equal to 10 then we
execute so if that's equal to like

00:08:28.539 --> 00:08:37.240 align:start position:19%
anything any crazy number that isn't 10
then it'll execute but if is 10 then you

00:08:35.380 --> 00:08:41.950 align:start position:19%
know it won't execute the code inside of
here all right so I'm sure you guys all

00:08:39.729 --> 00:08:47.120 align:start position:19%
recognize you know greater than and less
than fine so if we change this to a

00:08:44.829 --> 00:08:51.379 align:start position:19%
greater than if you know
X is greater than 10 then we'll execute

00:08:49.490 --> 00:08:56.569 align:start position:19%
the code inside of here so if we run
this it actually won't execute any code

00:08:53.660 --> 00:09:02.629 align:start position:19%
that's because 10 is not greater than 10
and you know the 10 goes for less than

00:08:59.829 --> 00:09:06.319 align:start position:19%
10 is not less than 10 so if we want the
numbers that we're comparing to be

00:09:04.490 --> 00:09:10.939 align:start position:19%
inclusive then that's actually where
these other operators comes in come in

00:09:08.089 --> 00:09:17.680 align:start position:19%
these two so if we use these these just
mean greater than or equal to so if X is

00:09:15.079 --> 00:09:23.839 align:start position:19%
anything greater than 10 so you know
anything above 10 then it will execute

00:09:20.720 --> 00:09:27.499 align:start position:19%
the code inside of here and if it is
equal to 10 then we'll also execute the

00:09:26.180 --> 00:09:31.790 align:start position:19%
code inside of here the same goes for
less than but sure you guys can figure

00:09:29.809 --> 00:09:36.259 align:start position:19%
that out all right so now that I've gone
on my talking spree about the logical

00:09:34.279 --> 00:09:39.529 align:start position:19%
operators let's talk a little bit more
about the if statement itself so

00:09:37.910 --> 00:09:45.709 align:start position:19%
specifically we're going to talk about
something called the else block and that

00:09:42.019 --> 00:09:52.220 align:start position:19%
looks like this so the else lock the
else block executes if the if statement

00:09:48.680 --> 00:09:55.759 align:start position:19%
does not execute so if this doesn't come
true if this never executes then we're

00:09:54.230 --> 00:10:00.439 align:start position:19%
going to execute what's inside the else
block so we can do I'm going to just

00:09:58.910 --> 00:10:06.949 align:start position:19%
write something in here to let us know
that this executed else

00:10:04.240 --> 00:10:13.370 align:start position:19%
executed so let me just change this to
is equal equal to 10 and it will change

00:10:09.980 --> 00:10:20.749 align:start position:19%
10 to something like 16 so when I run
this what it's doing is it's saying okay

00:10:16.490 --> 00:10:26.179 align:start position:19%
so is X equal to 10 know the value of X
is 16 so we're going to not execute this

00:10:23.720 --> 00:10:30.350 align:start position:19%
line and instead we're going to execute
this else statement because nothing up

00:10:27.980 --> 00:10:34.819 align:start position:19%
here was true so the else block is
executed and obviously the else block

00:10:32.809 --> 00:10:39.949 align:start position:19%
does not have a condition like up here
this is why it's missing parentheses is

00:10:36.589 --> 00:10:44.209 align:start position:19%
because it is executed if everything up
here is not executed regardless of what

00:10:42.379 --> 00:10:48.079 align:start position:19%
the condition is then there's one more
block I want to talk about I promise

00:10:45.649 --> 00:10:54.589 align:start position:19%
this is the last one and that is the
else if block I know there's a lot of

00:10:51.189 --> 00:10:59.120 align:start position:19%
stuff I'm saying but this is you know I
promise this last one so the elseis

00:10:56.689 --> 00:11:03.070 align:start position:19%
condition is checked after the initial
if statements condition

00:11:00.370 --> 00:11:05.830 align:start position:19%
checked so if this chunk does not run
we're going to check this condition

00:11:04.600 --> 00:11:10.779 align:start position:19%
which doesn't have anything in it for
now and if that's not run then we're

00:11:08.560 --> 00:11:16.089 align:start position:19%
going to execute this else statement so
let me just fill in an example condition

00:11:12.910 --> 00:11:26.320 align:start position:19%
here you know we'll say if it's well if
X is greater than 10 and then we'll do

00:11:19.830 --> 00:11:29.380 align:start position:19%
we'll just execute else if execute so in
this specific case let's just run

00:11:27.670 --> 00:11:34.660 align:start position:19%
through what the program is doing what
it's saying so it comes in here we're

00:11:31.990 --> 00:11:39.040 align:start position:19%
initializing X to the value 16 we're
saying if X is equivalent to 10 then

00:11:37.900 --> 00:11:43.240 align:start position:19%
we're going to execute this line
obviously the value 16 is not equivalent

00:11:41.770 --> 00:11:48.070 align:start position:19%
to 10 so let's move on we're going to
move on to this else s block if X is

00:11:45.880 --> 00:11:53.020 align:start position:19%
greater than 10 then we're going to
execute this line since 16 is greater

00:11:51.190 --> 00:11:57.370 align:start position:19%
than 10 we're going to execute this
block and we're going to skip over this

00:11:55.089 --> 00:12:01.990 align:start position:19%
else statement because something above
the else statement was run so similarly

00:11:59.890 --> 00:12:06.250 align:start position:19%
if this if condition is true and this
block is executed the program is going

00:12:03.790 --> 00:12:09.910 align:start position:19%
to skip over all the else if and the
else block because we already have a

00:12:08.110 --> 00:12:14.410 align:start position:19%
condition that's true up here so if we
come up here and we make this you know

00:12:11.350 --> 00:12:20.290 align:start position:19%
16 and of X is equal to 16 and it checks
and says oh f is X is equal to 16 then

00:12:18.190 --> 00:12:25.810 align:start position:19%
this line will execute and it's not even
going to check these bottom two and

00:12:21.880 --> 00:12:31.150 align:start position:19%
guess what Walker we can have as many of
these else if statements as we want we

00:12:28.510 --> 00:12:35.610 align:start position:19%
can have boom-boom-boom up to infinity
we can have a check if it is a greater

00:12:32.740 --> 00:12:42.700 align:start position:19%
than 11 is it greater than 12 this is
not equal to so whatever that number is

00:12:40.510 --> 00:12:47.080 align:start position:19%
it doesn't matter you can have as many
else ifs as you want and they're all

00:12:44.709 --> 00:12:52.180 align:start position:19%
going to sequentially check one after
the other until one is found and if one

00:12:49.540 --> 00:12:56.560 align:start position:19%
and it's not one condition is met then
this else block will just run so Michael

00:12:54.550 --> 00:13:00.640 align:start position:19%
why did we spend the last eternity
learning about if statements I just want

00:12:58.360 --> 00:13:05.020 align:start position:19%
to learn how to program stupid [&nbsp;__&nbsp;] this
this stuff is core this is like this is

00:13:03.640 --> 00:13:09.280 align:start position:19%
your bread and butter you're going to
want to you have to pick this up first

00:13:07.060 --> 00:13:12.830 align:start position:19%
if you want to learn calculus you got to
learn how to add first right maybe not I

00:13:11.770 --> 00:13:17.300 align:start position:19%
don't know I never took
so and no but you know point remains so

00:13:15.920 --> 00:13:20.779 align:start position:19%
that's it for this tutorial before I
wrap things up I wanted to you know give

00:13:19.399 --> 00:13:25.339 align:start position:19%
a shout out to everyone who came and
supported me for my patreon campaign

00:13:23.050 --> 00:13:29.060 align:start position:19%
it's been really great for the channel
and helping those productivity on videos

00:13:27.140 --> 00:13:32.060 align:start position:19%
if you haven't heard of it
get a head on over I'll leave a link

00:13:30.470 --> 00:13:36.230 align:start position:19%
there and down in the description and
consider supporting me if you enjoy what

00:13:34.459 --> 00:13:39.860 align:start position:19%
I make here that being said I know
today's topics were kind of seemed all

00:13:38.269 --> 00:13:43.190 align:start position:19%
over the place they kind of add a
context but I promise that next tutorial

00:13:41.959 --> 00:13:47.570 align:start position:19%
we're going to be putting them into a
practical project and that will help

00:13:45.740 --> 00:13:59.429 align:start position:19%
just bring everything together a lot
more nicely so yeah thanks for watching

00:13:50.550 --> 00:13:59.429 align:start position:19%
[Music]

