1 00:00:00,790 --> 00:00:06,500 Hello guys and welcome back to another class of our course about Python. 2 00:00:06,520 --> 00:00:12,660 So in this class we are going to talk once again about a very important thing in Python programming. 3 00:00:12,950 --> 00:00:16,820 And this is the while loop. 4 00:00:17,300 --> 00:00:21,660 So in this what what exactly is this while loop. 5 00:00:21,660 --> 00:00:28,110 What exactly is a loop is if for example you want to run a code a multiple amount of times. 6 00:00:28,130 --> 00:00:33,290 So let's say for example I want to run a quote code until a certain outcome have been reached. 7 00:00:33,360 --> 00:00:37,510 So let's say for example I want to reach a certain outcome I'm looking for a certain password for example 8 00:00:37,520 --> 00:00:43,320 this can be used in cybersecurity so let's say I want to make a brute force attack and I want to crack 9 00:00:43,380 --> 00:00:43,960 a password. 10 00:00:44,280 --> 00:00:46,980 So in this case I will run many passwords. 11 00:00:46,980 --> 00:00:55,400 I will run many combinations until the right combination I have has been let's say achieved were the 12 00:00:55,910 --> 00:01:00,620 well python have achieved the right combination. 13 00:01:00,630 --> 00:01:03,840 So this is exactly what we are going to learn today. 14 00:01:03,840 --> 00:01:09,450 You can use this well in that analysis you can use it in many many fields. 15 00:01:09,480 --> 00:01:11,100 So this is an important function. 16 00:01:11,180 --> 00:01:16,720 Once again it's not hard to understand once you'll see what it looks like. 17 00:01:16,740 --> 00:01:24,630 So let's start so the first thing we want to do will be have variables. 18 00:01:24,640 --> 00:01:33,040 So in this case we need to choose at least one variable and the let's say our variable will be. 19 00:01:33,040 --> 00:01:33,690 I don't know. 20 00:01:33,790 --> 00:01:40,920 Let's name it variable in this case is going to be variable one. 21 00:01:40,930 --> 00:01:49,030 All right let's say variable one will be equal to let's say twenty five and we'll have another variable 22 00:01:49,120 --> 00:01:57,910 which will be variable too so variable one and variable variable two will be equal to let's say 2000. 23 00:01:59,380 --> 00:02:00,010 All right. 24 00:02:00,970 --> 00:02:03,560 So we run a very very simple code. 25 00:02:03,640 --> 00:02:08,400 So in this case we want variable 1 to be greater than variable 2. 26 00:02:08,410 --> 00:02:16,100 So how we write this or let's say you write down well and in this case you write down your condition. 27 00:02:16,550 --> 00:02:20,910 So let's say variable 1. 28 00:02:21,180 --> 00:02:24,930 This case is greater than variable to 29 00:02:29,060 --> 00:02:31,150 so here we go. 30 00:02:31,180 --> 00:02:38,160 So until this condition is met the code that is here will be replaced. 31 00:02:38,170 --> 00:02:41,290 So until this condition is met the code will be replaced. 32 00:02:41,290 --> 00:02:44,150 So let me show you what it will look like. 33 00:02:44,620 --> 00:02:46,180 Let's say for example we want to print. 34 00:02:46,330 --> 00:02:48,950 We'll print our variable one. 35 00:02:49,620 --> 00:02:52,180 So we'll print two things we'll print viable one 36 00:02:56,270 --> 00:03:00,680 and as well as we'll print let's say doesn't work 37 00:03:04,900 --> 00:03:05,920 we're not good 38 00:03:14,190 --> 00:03:14,420 all right. 39 00:03:16,530 --> 00:03:24,660 And what exactly will be will be making as a calculation to in this case if we only print the variable 40 00:03:24,660 --> 00:03:30,870 one it will not make sense because what's going to happen is Python will run only this code and it's 41 00:03:30,870 --> 00:03:31,530 not going to change. 42 00:03:31,530 --> 00:03:35,480 So if we run our code as you can see it doesn't make sense. 43 00:03:35,490 --> 00:03:37,290 It will run until the infinite. 44 00:03:37,350 --> 00:03:43,260 So it will just run this code but it doesn't make sense because variable one will always be smaller 45 00:03:43,260 --> 00:03:43,950 than variable too. 46 00:03:44,940 --> 00:03:49,750 So let's thing let's say we want to add a calculation to what our variable. 47 00:03:49,770 --> 00:03:51,320 To group. 48 00:03:51,410 --> 00:04:01,700 So in this case let's say variable 1 will be equal to via variable 1 49 00:04:04,690 --> 00:04:07,740 plus let's say 5. 50 00:04:07,760 --> 00:04:09,470 So what the what this means. 51 00:04:09,530 --> 00:04:14,120 This simply means that we will run our courts will have our variable one. 52 00:04:14,150 --> 00:04:17,290 In this case it's 25 the first time. 53 00:04:17,340 --> 00:04:21,410 So what's going to happen is that python will run this code. 54 00:04:21,510 --> 00:04:25,370 So the first time that he will run the code variable one will be equal to twenty five. 55 00:04:25,470 --> 00:04:31,230 Then he will also print not good then variable one will be equal to variable one plus five. 56 00:04:31,500 --> 00:04:34,080 So once again variable one will become 30. 57 00:04:34,080 --> 00:04:36,930 In this case variable one becomes 30. 58 00:04:37,070 --> 00:04:39,100 So once again python will verify here. 59 00:04:39,110 --> 00:04:42,630 So here we have 30 30 still less than 2000. 60 00:04:42,650 --> 00:04:43,990 So we are going to rerun the code. 61 00:04:44,280 --> 00:04:50,330 And right now what's going to happen is variable one is 30 so variable one is equal to variable one 62 00:04:50,360 --> 00:04:51,830 plus five or 30 plus five. 63 00:04:51,830 --> 00:04:53,050 It's gonna become thirty five. 64 00:04:53,630 --> 00:05:00,070 So just look at the code and you'll see what exactly is happening here let's say we run our code once 65 00:05:00,070 --> 00:05:03,120 again and as you can see that's exactly what's happening. 66 00:05:03,400 --> 00:05:06,410 Each time the code is growing by five. 67 00:05:06,550 --> 00:05:12,760 And at the end it's reaching one to one thousand ninety five nine hundred ninety five. 68 00:05:13,660 --> 00:05:22,000 So until the moment that variable one is smaller than the variable to the code will continue to run 69 00:05:22,030 --> 00:05:25,990 but when it's reached at the end it's gonna stop running. 70 00:05:25,990 --> 00:05:31,570 So in this case it stopped running at one thousand ninety five hundred because the next the next jump 71 00:05:31,570 --> 00:05:39,010 the next it's in the next moment the variable one will be not greater but will be equal to variable 72 00:05:39,010 --> 00:05:39,560 number two. 73 00:05:39,580 --> 00:05:43,440 And this is why Python stopped at one variable list. 74 00:05:43,510 --> 00:05:50,170 Let's explain it has many many utilities in let's say in real life and this type of what this function 75 00:05:50,230 --> 00:05:55,930 is very very use that same cybersecurity if you want to for example crack passwords it can be used if 76 00:05:55,930 --> 00:06:00,300 you are looking for a certain output somewhere and you need to try many many things. 77 00:06:00,340 --> 00:06:04,960 Well it can use this function and once again you can write anything you want here. 78 00:06:04,960 --> 00:06:09,130 So let's say you hear it's just something that is very very simple. 79 00:06:09,130 --> 00:06:12,820 Once again you can write as I said very very complicated functions right there. 80 00:06:12,940 --> 00:06:18,370 And python will still run them until you have the output that you need. 81 00:06:18,370 --> 00:06:20,080 Exactly. 82 00:06:20,140 --> 00:06:25,330 So let's say you can change your variable to buy something else let's say you want to change it by 1000. 83 00:06:25,330 --> 00:06:32,000 In this case you want to change it by 1000 and we can just run our python and as you can see it's going 84 00:06:32,000 --> 00:06:32,670 to still work. 85 00:06:33,420 --> 00:06:35,730 So as you can see it's something that is very very cool. 86 00:06:35,790 --> 00:06:42,120 And once you know how to use it properly with all other functions you'll see you'll be able to do many 87 00:06:42,120 --> 00:06:43,690 many very interesting things with it. 88 00:06:44,070 --> 00:06:44,950 So that's it for this class. 89 00:06:44,950 --> 00:06:47,400 Guys in C in our next class.