WEBVTT 00:00:06.500 --> 00:00:13.170 In this video we're going to learn b while loops as we have covered in the javascript section. 00:00:13.380 --> 00:00:22.440 We know that while loops that will allow us to execute a piece of code at many times as far as a system 00:00:22.440 --> 00:00:24.150 condition is true. 00:00:24.720 --> 00:00:28.460 OK so let's build our first example. 00:00:28.530 --> 00:00:31.960 So first of all are going to define a variable. 00:00:32.170 --> 00:00:36.250 And are going to said does variable to one. 00:00:36.450 --> 00:00:48.090 OK and now we want to execute the following statements which is echoing by followed by a line break 00:00:50.200 --> 00:00:51.360 . 00:00:52.070 --> 00:00:58.490 And we want to execute these statements as far as it is less than 10. 00:00:58.590 --> 00:01:03.060 So let's copy the statements and delete it for now. 00:01:03.490 --> 00:01:06.700 So we're going to create a a while loop. 00:01:07.140 --> 00:01:12.960 So the syntax is similar to javascript's you're going to place the condition of the loop inside dependencies 00:01:13.050 --> 00:01:15.590 and then we're going to have curly brackets. 00:01:16.200 --> 00:01:21.590 OK where are we going to write our statements we want to execute many times. 00:01:21.630 --> 00:01:26.550 So the condition does we want is less than 10. 00:01:26.880 --> 00:01:37.140 OK so if we execute this code as as it is now the the one loop is going to continue forever. 00:01:37.300 --> 00:01:38.720 OK. 00:01:39.510 --> 00:01:46.000 So to avoid that we are going to change the value of every time we're on the statements. 00:01:46.140 --> 00:01:55.950 So we going to make I go up by one every time we run the statements and know what's going to happen 00:01:56.010 --> 00:02:05.040 is we're going to check the value of againstand in the first place at the beginning i.e. is equal to 00:02:05.040 --> 00:02:05.650 1. 00:02:05.670 --> 00:02:10.740 So this is going to be true so we're going to run this and then it becomes two and then we check again 00:02:10.760 --> 00:02:11.270 . 00:02:11.790 --> 00:02:14.490 Equal is equal to and it's less than 10. 00:02:14.640 --> 00:02:15.950 So it's fine. 00:02:15.960 --> 00:02:25.960 We echo again and then it becomes three or three carry and we continue until he is equal to nine. 00:02:26.170 --> 00:02:28.250 Then the condition is true. 00:02:28.340 --> 00:02:33.250 We we run the statements but this time I is going to be equal to 10. 00:02:33.360 --> 00:02:36.430 And the condition is not true. 00:02:36.450 --> 00:02:37.680 Are you going to stop there. 00:02:38.130 --> 00:02:44.620 OK so if we save and refresh we'll see that we have printed from 1 to 9. 00:02:44.880 --> 00:02:45.800 OK. 00:02:45.810 --> 00:02:55.530 If we want to bring I've from 1 to 10 we can just change this Lisen sign to listen sine or equal to 00:02:55.550 --> 00:02:55.700 . 00:02:55.830 --> 00:02:56.800 OK. 00:02:57.320 --> 00:02:59.840 If you say refresh you can see that 00:03:04.290 --> 00:03:06.060 we go until 10. 00:03:06.190 --> 00:03:08.540 OK fine. 00:03:09.180 --> 00:03:13.170 Now we are going to move to a raise. 00:03:13.890 --> 00:03:17.190 So let's see how to use the while loop within the range. 00:03:17.190 --> 00:03:25.170 So this creates a simple numerical rate comics and let's 00:03:27.810 --> 00:03:32.280 define three elements. 00:03:33.580 --> 00:03:34.360 OK. 00:03:34.560 --> 00:03:35.940 So as with BMW 00:03:39.900 --> 00:03:42.700 and Mercedes. 00:03:44.000 --> 00:03:45.030 OK. 00:03:45.600 --> 00:03:47.520 So now we want to 00:03:50.550 --> 00:03:55.650 echo all the values of our. 00:03:56.460 --> 00:03:57.250 Right. 00:03:57.360 --> 00:03:59.580 But using a while loop. 00:04:00.060 --> 00:04:10.620 OK so the statement is going to be Ecko and this time is going to be different from the for loop. 00:04:10.620 --> 00:04:17.430 So we're going to use the we're going to access the elements of the array using the array name followed 00:04:17.430 --> 00:04:27.210 by brackets and then inside the Rockets we're going to use the numeric index of of these elements. 00:04:27.270 --> 00:04:31.420 So are you going to use a variable J. 00:04:31.770 --> 00:04:33.520 Ok that. 00:04:33.870 --> 00:04:42.480 And every time we echo the value we want to follow is by a brick. 00:04:45.400 --> 00:04:49.180 OK so let's copy this one now just a little. 00:04:49.430 --> 00:04:53.040 So we want a variable J. 00:04:53.130 --> 00:04:53.890 So we're going to define it. 00:04:53.910 --> 00:04:56.730 And I'm going to set it to zero. 00:04:57.430 --> 00:04:57.880 OK. 00:04:57.930 --> 00:05:06.930 Because the first index is there and the condition is going to be J. 00:05:07.230 --> 00:05:08.970 Less than three. 00:05:10.160 --> 00:05:11.390 OK. 00:05:11.490 --> 00:05:19.590 And then inside curly brackets we writes are statements that we want to increment J. 00:05:19.590 --> 00:05:24.770 Every time by one case every time we execute our statements. 00:05:24.780 --> 00:05:28.010 Day goes up by 1. 00:05:28.440 --> 00:05:37.950 If we save and refresh the page we can see that we have printed all the array's elements values. 00:05:38.190 --> 00:05:39.410 OK. 00:05:40.210 --> 00:05:41.340 The first one to the last one 00:05:41.350 --> 00:05:48.060 .