1 00:00:11,900 --> 00:00:13,860 Hello, everybody, how are you? 2 00:00:14,690 --> 00:00:21,830 Now, we have completed the Four Loops series and we have seen lots of examples, I think that we are 3 00:00:21,830 --> 00:00:25,850 ready to study its twin brother in for loops. 4 00:00:25,850 --> 00:00:34,070 We have seen statements which helped us to sort of lead the code inside in Eve or inside itself. 5 00:00:34,410 --> 00:00:42,770 And we were scanning lots of variables or collections with the hand of the for loop and applying some 6 00:00:42,770 --> 00:00:44,950 actions upon the cells of a collection. 7 00:00:45,590 --> 00:00:51,020 So while LOOP is a bit different, let's start from the top and see the difference between the two loops. 8 00:00:51,710 --> 00:00:52,090 All right. 9 00:00:52,250 --> 00:00:59,930 So a take Python programming language repeatedly executes the code inside it as long as a given condition 10 00:00:59,930 --> 00:01:00,520 is true. 11 00:01:00,860 --> 00:01:08,600 So you can see right here that we have sort of condition once we declare while we didn't have it in 12 00:01:08,600 --> 00:01:11,890 for info Oprah just mentioned, what do we want to scan? 13 00:01:11,900 --> 00:01:17,900 For example, we have a list or we have a range, meaning we have certain number one, certain times 14 00:01:17,930 --> 00:01:19,160 the loop that will run. 15 00:01:19,430 --> 00:01:24,560 But we didn't have any condition, like practically we didn't could not declare a certain condition 16 00:01:24,560 --> 00:01:25,250 that we want. 17 00:01:25,970 --> 00:01:28,120 So in wireless, we do have it. 18 00:01:28,460 --> 00:01:32,990 So let's see quickly the differences between for and while loops. 19 00:01:33,680 --> 00:01:40,780 So we have seen that for loops we're scanning in sort of speak collections or variables one by one. 20 00:01:41,720 --> 00:01:49,670 Then after we were focused on a certain cell or some other variable, we added and if statement that 21 00:01:49,670 --> 00:01:59,210 could apply the upon the code inside the for loop, we had an if statement and each cell in our examples, 22 00:01:59,660 --> 00:02:04,820 we could determine what to do with it, like whether we want this element to apply a certain action 23 00:02:05,120 --> 00:02:09,020 or simply go to else and do not apply any action. 24 00:02:09,110 --> 00:02:12,560 So we had an, if else, statements inside the follow up. 25 00:02:12,770 --> 00:02:19,160 This is what helped us to navigate the code inside the for loop in while loops. 26 00:02:19,160 --> 00:02:21,650 It's a bit different in Y loops. 27 00:02:21,650 --> 00:02:25,250 We mention a condition right where we declare the loop. 28 00:02:25,730 --> 00:02:32,510 OK, so once we declare that we have a wire loop, we have a wire loop right there in the same line, 29 00:02:32,540 --> 00:02:38,480 we declare a certain condition what we didn't have in for loops in four follow ups. 30 00:02:38,480 --> 00:02:42,820 We had some conditions, some statements inside the fall. 31 00:02:42,830 --> 00:02:48,530 But right here in while loops, we declare a condition right where we declare the loop itself. 32 00:02:49,010 --> 00:02:51,740 And as long as the condition is true. 33 00:02:53,110 --> 00:02:57,190 We will keep running cycles upon the fire, upon the wire. 34 00:02:57,990 --> 00:03:05,000 What that basically means, we'll have cycles going again and again as long as this condition is true, 35 00:03:05,310 --> 00:03:05,750 OK? 36 00:03:06,110 --> 00:03:09,180 We've seen examples and example in a few seconds. 37 00:03:10,680 --> 00:03:16,890 OK, so the simplest way we can create a variable, just simply create a variable and you can call it 38 00:03:16,900 --> 00:03:18,300 no equals zero. 39 00:03:18,810 --> 00:03:21,950 This will work as our counter, basically. 40 00:03:21,960 --> 00:03:27,930 In other words, this will be the condition that we will check in every cycle of the wild. 41 00:03:28,480 --> 00:03:34,160 OK, so then we define a wire loop with a condition. 42 00:03:34,410 --> 00:03:36,270 The condition is the following thing. 43 00:03:36,580 --> 00:03:40,590 As long as no is smaller than 10, continue running. 44 00:03:40,770 --> 00:03:46,480 OK, so the beginning number equals zero equals zero. 45 00:03:46,500 --> 00:03:47,900 You can see where my mouth is. 46 00:03:48,150 --> 00:03:49,620 So number equals zero. 47 00:03:49,650 --> 00:03:51,390 Then we declare here a while. 48 00:03:51,540 --> 00:03:57,720 This is the key word for a while loops and then we set the condition in our in our example, it's no 49 00:03:57,720 --> 00:04:02,490 smaller than ten, but for now number equals zero zero. 50 00:04:02,490 --> 00:04:09,900 And if we run this cycle, this while loop again and again without growing our number, a variable number, 51 00:04:09,900 --> 00:04:11,470 if it's just stays zero. 52 00:04:11,490 --> 00:04:17,520 So it's an endless loop and can cause lots of trouble for our programmers, for programmers, whether 53 00:04:17,520 --> 00:04:20,520 they're web developers or back in front, it doesn't matter. 54 00:04:20,730 --> 00:04:23,790 Once you have an endless loop, it gets stuck in the whole system. 55 00:04:24,270 --> 00:04:31,410 Your whole computer or your server can break down because you had an endless loop and can crash your 56 00:04:31,620 --> 00:04:32,270 systems. 57 00:04:32,280 --> 00:04:32,580 All right. 58 00:04:33,270 --> 00:04:36,810 So we can't have this we can't have an endless loop in our code. 59 00:04:37,140 --> 00:04:41,430 And what we are willing to do, you can see the dots part right here. 60 00:04:41,710 --> 00:04:48,060 OK, so right here at the bottom, we have no plus equals one. 61 00:04:48,540 --> 00:04:51,140 OK, number plus equals one. 62 00:04:51,780 --> 00:04:58,230 What that means is what that means is, is basically this thing the same thing number equals number 63 00:04:58,350 --> 00:04:58,950 plus one. 64 00:04:59,520 --> 00:05:06,060 What you seen in the in the here in the example, in the code example the number equals the number of 65 00:05:06,060 --> 00:05:10,100 plus equals one is just a short way to write this thing. 66 00:05:10,830 --> 00:05:15,930 OK, number what we have current value growth by one. 67 00:05:16,440 --> 00:05:18,100 OK, so just going to erase it. 68 00:05:19,680 --> 00:05:22,000 So what we want to do. 69 00:05:22,020 --> 00:05:22,730 OK, ok. 70 00:05:22,740 --> 00:05:28,950 This part with a dot, it's inside the wire loop so each time the will run this call in the dots will 71 00:05:28,950 --> 00:05:29,770 be executed. 72 00:05:29,790 --> 00:05:37,110 So basically what we're saying here is each time you run the cycle, grow the variable number by plus 73 00:05:37,110 --> 00:05:37,520 one. 74 00:05:37,980 --> 00:05:41,330 So we start with this with zero and we get here. 75 00:05:41,700 --> 00:05:43,380 Here we're seeing growing by one. 76 00:05:43,770 --> 00:05:47,350 Then we go to the top again to the wild condition. 77 00:05:47,910 --> 00:05:53,940 OK, now the number, the variable here, it doesn't equal zero like we're declaring it. 78 00:05:54,030 --> 00:05:57,130 No, we have grabbed it by one right here at the bottom. 79 00:05:57,150 --> 00:05:59,460 So right now, number equals one already. 80 00:05:59,940 --> 00:06:02,520 So we execute the code again and again. 81 00:06:02,780 --> 00:06:03,840 Again and again. 82 00:06:04,080 --> 00:06:08,700 Up until the fall of the wild condition here would be false. 83 00:06:09,630 --> 00:06:13,830 Or in other words, as long as it's true, it will run again. 84 00:06:14,400 --> 00:06:24,210 So once we get here to 10, once we have here nine plus one and we go again to the top on the 10th cycle. 85 00:06:24,510 --> 00:06:32,220 So we'll have your number smaller than ten, which is ten, smaller than 10 once. 86 00:06:32,230 --> 00:06:33,780 This statement will be false. 87 00:06:33,810 --> 00:06:34,770 It would be a light. 88 00:06:35,760 --> 00:06:41,020 The code will exec exit the wire loop and go with the flow of code. 89 00:06:41,040 --> 00:06:44,940 What we have after the wild, it will exit the wild completely. 90 00:06:45,330 --> 00:06:50,780 So just want to just want a market once the value here would be ten. 91 00:06:51,240 --> 00:06:55,940 OK, this would be a false statement and then while Loop will be exited. 92 00:06:56,370 --> 00:06:56,840 All right. 93 00:06:57,780 --> 00:06:58,730 So that's it. 94 00:06:58,740 --> 00:06:59,100 It's plain. 95 00:06:59,130 --> 00:06:59,520 Simple. 96 00:06:59,520 --> 00:07:00,530 It's not very hard. 97 00:07:00,780 --> 00:07:03,780 Once you understood the four loops, this is piece of cake. 98 00:07:03,960 --> 00:07:05,370 You just have here a condition. 99 00:07:05,520 --> 00:07:10,290 You can set it here, whatever you want, whether a number or a letter or doesn't matter. 100 00:07:10,440 --> 00:07:17,430 And as long as this statement right here is through the cycle, what under the wire loop will keep running 101 00:07:17,430 --> 00:07:22,140 again, as will go from the top again and check the condition and run to the bottom and then again from 102 00:07:22,140 --> 00:07:23,430 the top and so on and so on. 103 00:07:23,670 --> 00:07:28,190 And you have to find a way to stop the while loop so it will not run forever. 104 00:07:28,380 --> 00:07:33,030 And this you do by changing variables inside the content of your while loop. 105 00:07:34,230 --> 00:07:39,180 So that's the theoretical sketch, for example, for for a second to see what we just seen here. 106 00:07:39,990 --> 00:07:43,280 So basically just start the module with a while. 107 00:07:43,790 --> 00:07:47,610 For example, you have a certain module that you have only a while openside. 108 00:07:48,030 --> 00:07:52,570 So you start running the module and then you get to a condition of. 109 00:07:52,660 --> 00:07:59,210 That while loop in this condition, we check if the statement is true, they called on their while loop 110 00:07:59,230 --> 00:08:03,390 will run and then you go again to the condition to the top. 111 00:08:03,760 --> 00:08:05,710 Then again, the condition is checked. 112 00:08:05,980 --> 00:08:07,790 If it's true, it will run again. 113 00:08:08,060 --> 00:08:11,150 OK, up until the condition would be false. 114 00:08:11,290 --> 00:08:16,390 Once the condition on the top would be false, the cold will exit your wirewood. 115 00:08:16,810 --> 00:08:17,380 That's it. 116 00:08:17,710 --> 00:08:18,690 Plain, simple. 117 00:08:19,270 --> 00:08:23,650 I think this theory covered the basics of a wild pretty easily. 118 00:08:23,830 --> 00:08:26,640 And you can see an example here to apply the rules. 119 00:08:26,650 --> 00:08:34,810 As we just discussed, we will go further to the next lecture by seeing advanced dance characters off 120 00:08:34,810 --> 00:08:37,840 while loops and also live examples as well. 121 00:08:38,170 --> 00:08:44,350 And right after we go to the practice part, I don't worry about it because it's pretty easy to understand. 122 00:08:44,350 --> 00:08:50,680 Once you once you get once you get the rule here and this is just mentioned, you will see many examples 123 00:08:50,680 --> 00:08:52,000 in the next lectures. 124 00:08:53,150 --> 00:08:55,390 And I think that you could get the hang of it. 125 00:08:55,390 --> 00:08:56,080 I'm sure of it. 126 00:08:56,470 --> 00:08:57,750 And that's about it. 127 00:08:57,910 --> 00:09:00,810 I think we closed up this lecture the next one. 128 00:09:00,970 --> 00:09:02,170 Thank you and bye bye.