WEBVTT

00:00.180 --> 00:06.810
Let's start with violence, one of the most important concepts in programming, and before you learn

00:06.810 --> 00:11.310
what is valuable, please let me explain to you quickly why you need them.

00:11.760 --> 00:16.460
So here is the first program we have written to make an editor blink.

00:16.800 --> 00:22.980
And as you can see, so we need first to initialize the entity by providing the PIN number.

00:23.160 --> 00:25.380
And then when we want to use digital right.

00:25.380 --> 00:27.390
We also need to provide the PIN number.

00:27.720 --> 00:34.470
Look, in this program, whenever you want to change the data center, you use PIN number even when

00:34.560 --> 00:37.490
you need to change these three times.

00:38.070 --> 00:41.550
And this is maybe not the most convenient thing to do.

00:42.160 --> 00:48.180
Also, this program is rather small, but now imagine that you have a program that is one hundred line

00:48.450 --> 00:52.710
long and you need to change that seven times in the program.

00:52.980 --> 00:56.010
Well, this is a quick way to make errors.

00:56.370 --> 01:00.140
So here what we are going to do is we are going to use variables.

01:00.750 --> 01:09.100
So I'm going to create just a viable and then explain what our variables, let's say, into the thing

01:09.420 --> 01:10.710
is equal to 12.

01:11.830 --> 01:13.810
So if I do this.

01:15.020 --> 01:17.720
And I replaced where we've been.

01:19.350 --> 01:26.650
All right, now, if I want to change the editing, I just need to change it once here.

01:27.090 --> 01:27.390
OK?

01:27.420 --> 01:34.180
And whenever I write any dippin the value here, so it will be replaced by 12.

01:34.440 --> 01:35.470
OK, so no effect.

01:35.490 --> 01:37.980
But even I have the same program.

01:38.160 --> 01:40.250
But using the pin Edvin.

01:40.650 --> 01:48.930
So what is a viable viable represents the stored value that you can reuse later in your program.

01:49.320 --> 01:55.820
It's kind of a container and to make it easier to recognize it, you can give it to name.

01:56.250 --> 01:58.160
So I'm going to create a new find.

02:01.270 --> 02:09.010
And I'm going to create viable here to create a viable first, you need to give a type of data type.

02:09.010 --> 02:12.610
So among the most common data type, you have it.

02:12.610 --> 02:15.280
And you can see when I put it, you have the column.

02:16.210 --> 02:19.910
So it means integer and it is a round number.

02:19.930 --> 02:27.060
So, for example, zero one, two, three, but also in the negative like minus five, minus 10, etc..

02:27.190 --> 02:29.270
So now you need to be the name.

02:29.290 --> 02:35.540
Let's put a fono and a semicolon to declare the variable.

02:35.560 --> 02:37.510
So there are actually two steps.

02:37.510 --> 02:44.890
When you create a viable first, you need to declare eight and then you can initialize it so you can

02:44.890 --> 02:46.210
give it a value.

02:46.450 --> 02:47.950
So let's say but seven.

02:48.550 --> 02:54.420
OK, and I don't forget the semicolon after initialized available here, I declare a viable.

02:54.430 --> 02:55.510
There is no value in it.

02:55.780 --> 02:59.640
And here I initialize the variable that was declared previously.

02:59.890 --> 03:08.830
I can also initialize the variable in the setup and if I want, I can directly also initialize the variable

03:08.950 --> 03:09.370
here.

03:09.850 --> 03:13.950
So here I declare and I initialized available at the same time.

03:14.200 --> 03:15.370
And what will happen here?

03:15.400 --> 03:21.970
So first, the lines on the top of the program will be basically where you declare your valuables.

03:21.990 --> 03:23.680
So this will be executed first.

03:23.950 --> 03:29.920
And then, as you know, the void set up would be executed and then the loop would be executed forever.

03:30.490 --> 03:37.980
So what will happen in this case is first we create a viable so we declare a and we initialize a two

03:37.990 --> 03:38.550
five.

03:38.860 --> 03:40.600
Not when we enter the setup.

03:41.080 --> 03:43.330
We simply change the value inside.

03:43.330 --> 03:47.410
A valuable is not a constant value unless you specify it.

03:47.440 --> 03:50.950
It's a container where you can change the value at any moment.

03:51.230 --> 03:53.770
Of course, you need to make sure this is the same data type.

03:53.770 --> 03:54.780
So integer.

03:55.120 --> 03:59.410
So let's for example, let's do that begin.

04:01.930 --> 04:09.430
OK, with nine thousand six hundred, so print and then and yeah, before we have just printed some

04:09.430 --> 04:16.630
text, but you can directly put the name of a valuable and this will print the name of the label.

04:16.630 --> 04:19.450
So let's name this program violence.

04:21.710 --> 04:27.350
OK, and make sure you already know is correctly connected, and now if I open the science monitor,

04:27.620 --> 04:35.990
I will see the value seven, OK, because A was equal to five first and then I changed the value inside

04:35.990 --> 04:40.420
A and I print an A whenever you use the name of available.

04:41.030 --> 04:47.540
What we really happen in the program is that the name of the variable will be replaced what we call

04:47.540 --> 04:57.500
evaluated to its value, which is said you can also use operators like plus minus etc. to put a value

04:57.500 --> 04:57.920
inside of.

04:58.320 --> 05:03.650
So not like this, we should see a equal to even.

05:05.080 --> 05:12.430
OK, so now A is equal to error, and you can also use a viable to create another viable, let's say,

05:12.430 --> 05:13.330
create another one.

05:13.330 --> 05:15.310
So I could create that.

05:15.310 --> 05:17.620
I'm going to create the I could create it here.

05:17.620 --> 05:19.480
So declare it here, for example.

05:19.930 --> 05:26.770
And then but B is equal to, let's say A plus or OK.

05:26.770 --> 05:28.300
And let's print the.

05:30.150 --> 05:38.550
So now A is equal to anyone at this line, and B will be equal to A plus false or B will be equal to

05:38.550 --> 05:39.300
15.

05:39.600 --> 05:46.550
So you can combine variables together and note that whenever you write a viable source, you write a

05:46.710 --> 05:49.590
A will be evaluated to its last value.

05:49.600 --> 05:53.870
So the value it has here and not the value here, OK.

05:53.970 --> 05:58.310
The order of the instructions is very important.

05:58.320 --> 06:05.370
Not if I do this, then you will see that B will not be equal to eight to 15.

06:05.370 --> 06:13.460
Sorry, that will be equal to nine because it was five and five plus four equals nine and then eight

06:13.480 --> 06:13.970
changes.

06:14.610 --> 06:17.460
OK, so that basically is how you use violence.

06:17.460 --> 06:22.880
And we are going to see more about that in the following of this course when we do many activities.

06:23.280 --> 06:27.510
And I briefly talked about constant variables.

06:27.510 --> 06:29.000
What are constant variables?

06:29.010 --> 06:33.960
Well, as you can see, a variable is a continuum where you can change the value at any time.

06:34.380 --> 06:39.060
But maybe you want to create some variables where the value can't be changed.

06:39.270 --> 06:40.710
And why is that, for example?

06:40.720 --> 06:46.370
Well, at the beginning of this lesson, I used available to store the PIN for analogy.

06:46.710 --> 06:52.470
And the thing is that once you have put the pin for the eight, it's been twelve in your program.

06:52.470 --> 06:55.570
You're not going to change it while you're on the program, OK?

06:55.650 --> 06:58.280
When you run the program, the hardware set up doesn't change.

06:58.530 --> 07:00.960
So in this case, you will use constants.

07:00.960 --> 07:03.690
So there are different ways to create constants.

07:03.690 --> 07:09.540
But here what I'm going to do is to use define so hashtag and define.

07:09.990 --> 07:12.150
You can see here it should turn green.

07:12.690 --> 07:20.010
OK, and then the convention to create variables which are constant is to use all the keys.

07:20.310 --> 07:30.000
But it's been so all keys and separate the world with and underscore and then you put the value, you

07:30.000 --> 07:31.720
don't put an equal sign.

07:31.740 --> 07:32.970
OK, this is different.

07:32.980 --> 07:40.820
So I shouldn't define the name of the variable in either case, the value of the value.

07:41.250 --> 07:43.800
And now you can use that in your program.

07:43.800 --> 07:48.330
And if you try to modify this, this simply won't work.

07:48.840 --> 07:53.010
OK, so you have normal variables and variables that you don't want to change in your program.

07:53.430 --> 08:00.180
So to quickly recap here, a valuable is a container you can use to store a value so that you can reduce

08:00.180 --> 08:06.510
that value later in your program to create a viable without when you first need to declare it with a

08:06.510 --> 08:13.290
name and a data type, then you can give it any value so you can initialize it here and give it any

08:13.290 --> 08:19.740
value all along your program, just making sure that the value stays in the data that you have chosen

08:20.040 --> 08:22.800
and you can create constant viable like this.
