WEBVTT

00:00.590 --> 00:03.500
I will call you back again to our another video lecture in PHP.

00:03.500 --> 00:10.040
And in this video lecture I will go ahead and teach you about why in PHP.

00:17.510 --> 00:17.870
All right.

00:17.870 --> 00:23.960
So in PHP we have what is called a loop system, which makes a program to run repeatedly.

00:23.960 --> 00:27.590
It makes a program to be able to execute multiple times.

00:27.710 --> 00:37.790
Let's go ahead and say I want to equal let's say equal one plus semicolon and save this.

00:37.790 --> 00:39.770
And let's refresh this one.

00:40.250 --> 00:41.720
I'll go ahead and copy this.

00:42.110 --> 00:45.890
Then I'll go ahead and paste this multiple times.

00:47.000 --> 00:47.330
All right.

00:47.330 --> 00:59.300
So I'm going to say equal two equal three equal four and five.

00:59.330 --> 01:00.710
Now let's save this.

01:01.140 --> 01:05.850
So if I got it on a fresh piece, have one, two, three, four, five.

01:06.570 --> 01:07.440
You see that?

01:07.470 --> 01:13.230
Now if you want to, you can actually put that to be one output to break.

01:14.310 --> 01:22.950
And in a way I can go ahead and copy this and press ahead and paste this.

01:25.380 --> 01:26.040
Right here.

01:26.760 --> 01:34.800
So because it changes again to 234 and five.

01:34.800 --> 01:36.630
So this kind of refreshes and check it out.

01:36.630 --> 01:38.280
So 12345.

01:38.280 --> 01:39.810
So you can see how long it takes me.

01:39.810 --> 01:46.620
It takes me about uh five lines of code to be able to print out 1234, five.

01:46.650 --> 01:52.170
Now imagine if I want to print out this 1 million or I want to print out 2 million.

01:52.200 --> 01:56.880
It means I have to equal out these four up to 2 or 3 million.

01:57.630 --> 02:04.100
Now I'll go ahead and get rid of this random of this, and we'll show you how we can be able to do that

02:04.100 --> 02:05.420
using a loop system.

02:05.420 --> 02:10.220
So that is if you want to be able to print out just like we did this.

02:10.250 --> 02:17.780
Now let's go ahead and create a variable and uh, let me say um variable known.

02:17.780 --> 02:19.430
So I'm going to call that to be known.

02:19.460 --> 02:21.020
And we want to print out numbers.

02:21.020 --> 02:25.190
And uh num is equal to one starting from one.

02:25.220 --> 02:27.080
That is where I want to start.

02:27.770 --> 02:32.750
Now what I need now is I have to create a statement called a while loop.

02:32.780 --> 02:37.130
So is a kind of a loop system called Y.

02:37.130 --> 02:39.200
And I want to hit on enter.

02:39.230 --> 02:41.780
You see that it gives the condition by itself.

02:41.780 --> 02:46.580
So y the very first one is uh the variable name.

02:46.580 --> 02:47.840
So y known.

02:47.870 --> 02:51.110
You can change that to any name is less than or equal to ten.

02:51.140 --> 02:51.320
Okay.

02:51.320 --> 02:52.130
Let me start with ten.

02:52.160 --> 02:53.270
That is what is given there.

02:53.270 --> 02:58.520
I can say maybe 20 or 5000 millions and so on.

02:58.760 --> 03:03.270
Now you go right in here A and that is the condition we are looking at.

03:03.300 --> 03:06.870
We are always going to take from 1 to 10.

03:07.170 --> 03:09.870
Now how are you going to do that?

03:09.900 --> 03:17.820
I will now go ahead and echo and will pass in a string right in there, and I will pass in that variable

03:17.820 --> 03:18.780
we just created.

03:18.780 --> 03:21.060
So known.

03:21.180 --> 03:26.310
And then for anytime I pass known, I want to move to the next line so that you can be able to see the

03:26.310 --> 03:29.370
variable whatever we are printing out.

03:29.760 --> 03:31.440
So now let's go ahead and print this out.

03:31.470 --> 03:35.700
I save this and you can see I have one being printed to infinity.

03:35.820 --> 03:43.380
Now what happens is that we do give a condition that we want this to be able to increment to one, two,

03:43.410 --> 03:43.740
three.

03:43.740 --> 03:48.180
So whenever it comes here it says one is less than or equal to ten.

03:48.210 --> 03:50.220
It brings that out whenever it comes.

03:50.250 --> 03:52.290
It said one is less than or equal to ten.

03:52.320 --> 03:53.490
It prints that out.

03:53.490 --> 03:58.560
And if you can watch my system, I'm scrolling down and this is printing to infinity.

03:58.590 --> 03:59.520
You understand.

03:59.520 --> 04:02.680
So That is an infinite loop.

04:02.680 --> 04:04.540
You can see I'm still squaring down.

04:04.540 --> 04:12.550
So now what I want to do is I want to give a condition that when one comes is printed at the first time,

04:12.550 --> 04:19.210
it goes back to the condition at check and it will increment and then go back to the condition.

04:19.210 --> 04:23.530
I check and come back and increment until it gets to ten.

04:23.560 --> 04:35.800
Now I'll go over here and I'm going to say put in the variable name known, and I'm going to see known

04:35.830 --> 04:37.570
increment two times.

04:37.570 --> 04:40.990
So that addition means increment twice.

04:40.990 --> 04:43.780
So what it means is that I will refresh this.

04:43.810 --> 04:44.830
Let's check it out.

04:45.580 --> 04:46.570
It goes the first one.

04:46.600 --> 04:49.060
You see that I need to print 1 to 10.

04:49.090 --> 04:52.030
It goes the first time and print out one.

04:52.060 --> 04:54.580
Then it goes back and check the condition.

04:54.580 --> 05:00.610
And the condition sees increment again and one to the variable making it two.

05:00.640 --> 05:02.210
Then it prints out two.

05:02.240 --> 05:08.690
Then it goes back again and check and it says add another one to that and check if it is less than ten.

05:08.720 --> 05:16.550
It increments again, and when it gets to ten it says keep adding, but always check if it is below

05:16.550 --> 05:16.940
ten.

05:16.940 --> 05:18.380
So when it gets to ten it adds.

05:18.380 --> 05:20.300
And that is that is 11.

05:20.330 --> 05:25.580
It goes back as a no 11 is greater than ten, 11 is not less than.

05:25.580 --> 05:26.900
And it breaks out.

05:27.410 --> 05:31.970
So it stops at anything less than ten.

05:32.060 --> 05:36.500
So if you set this to start from zero, go ahead and put a zero right in and save this.

05:36.530 --> 05:39.890
I refresh this and you can see I started from zero.

05:40.130 --> 05:48.140
And it remains to one two because it starts at 12345678 9 to 10.

05:48.170 --> 05:50.900
Now I said this is less than or equal to ten.

05:50.930 --> 05:55.070
What if I say this is less than ten and the guy had on a fresh.

05:55.100 --> 05:59.450
You can see that ten is not included because it must be less than ten.

05:59.570 --> 06:02.050
What if I said less than or equal to ten.

06:02.080 --> 06:03.880
It means that ten is included.

06:04.690 --> 06:08.920
So this is about while loop in PHP.

06:08.950 --> 06:12.040
So I believe that's all from the explanation you got.

06:12.070 --> 06:16.720
How and why we are using while loop in case you want to print out hundred.

06:17.260 --> 06:22.900
So you can actually use it to print out hundred and say this is hundred.

06:22.960 --> 06:27.640
And let's go ahead and okay, let me just select 20 because this might be very long.

06:27.670 --> 06:30.160
Let's say 20 and refresh.

06:30.160 --> 06:31.330
And we get down.

06:31.330 --> 06:33.160
You can see I have 20 down here.

06:33.160 --> 06:39.610
So if I do dot 200 I have to scroll down all the way down to hundred for you to see that.

06:39.610 --> 06:41.770
So go ahead and play around with them.

06:41.770 --> 06:46.360
You can do that 200 and scroll down to the bottom of your browser.

06:46.360 --> 06:48.100
And you can see 100 down there.

06:48.100 --> 06:50.410
So check it out, play around with it.

06:50.410 --> 06:55.000
And if you have if you have any question, go ahead and use the question and answer section.

06:55.000 --> 06:57.640
And I'm going to get back to you as soon as possible.

06:57.670 --> 06:58.720
Thank you so much.

06:58.720 --> 07:01.990
And I'm going to see you in the next video lecture.
