1 00:00:00,060 --> 00:00:00,870 Hello, everyone. 2 00:00:01,650 --> 00:00:08,460 Today, we will continue our best scripting videos with while use a while loop in any programming language 3 00:00:08,460 --> 00:00:13,890 is to repeat the same line or a set of lines over and over until you meet a certain condition. 4 00:00:15,360 --> 00:00:16,440 Let's take an example. 5 00:00:20,800 --> 00:00:25,340 In this script, we're creating a variable eye and assigning it a value of zero. 6 00:00:26,950 --> 00:00:31,270 Then we build a while loop by checking if I is less than or equal 10. 7 00:00:32,200 --> 00:00:34,420 If it's not, then echo this line. 8 00:00:38,760 --> 00:00:44,520 But it's very important to keep in mind that if we close our script like this, it will run forever 9 00:00:45,210 --> 00:00:47,620 because I will be zero forever, right? 10 00:00:48,900 --> 00:00:54,480 So basically I will be less than 10 and it will never become 11 for the loop to stop. 11 00:00:55,950 --> 00:00:58,410 So let's change the value of AI inside our. 12 00:01:34,090 --> 00:01:34,600 Noice. 13 00:01:36,380 --> 00:01:42,740 We can also have an infinite while loop without any condition to stop it, but then we have to specify 14 00:01:42,740 --> 00:01:45,920 our own condition inside the loop in order to stop it. 15 00:01:47,060 --> 00:01:47,960 Let's take an example. 16 00:01:49,700 --> 00:01:56,480 In this example, we're creating an infinite while loop just by adding colon after the word while here. 17 00:02:00,280 --> 00:02:05,680 Then we will keep reading a number from the user and tell the number we're reading is bigger than hundred. 18 00:02:09,610 --> 00:02:13,780 If that's the case, then we break our law by using the word break. 19 00:02:16,610 --> 00:02:17,840 Let's try it out in action. 20 00:02:35,100 --> 00:02:43,780 Nice, as you noticed, our look only stopped when we entered hundred and one, which is greater than 21 00:02:43,800 --> 00:02:44,240 a hundred. 22 00:02:45,750 --> 00:02:50,070 A very useful example of using one is to read data from a file. 23 00:02:51,210 --> 00:02:52,020 Let's take a look. 24 00:02:53,640 --> 00:02:56,070 First, we have a file here called Passwords. 25 00:02:59,220 --> 00:03:02,120 This file has two columns separated by space. 26 00:03:02,820 --> 00:03:09,720 We kind of did this before using OK, remember, let's do that now and said our best fit 27 00:03:16,410 --> 00:03:21,810 in this group we're using while loop to keep reading data and stored in a variable called line. 28 00:03:25,160 --> 00:03:37,790 Then we are assigning the output of this command here to user and the output of this command to pass. 29 00:03:39,560 --> 00:03:46,700 We explained this command before, but in general we are splitting each line into two fields, separated 30 00:03:46,700 --> 00:03:47,320 by space. 31 00:03:47,810 --> 00:03:50,420 Then we take the first column, which is No. 32 00:03:50,420 --> 00:03:58,490 One here for the username, and we do the same, but for column number two for the password. 33 00:04:00,990 --> 00:04:04,050 Then we split them again, using common here. 34 00:04:06,790 --> 00:04:10,360 Then we call the two variables in this line. 35 00:04:11,830 --> 00:04:17,160 Finally at the bottom, we're taking input from my file, which is defined at the top of the script 36 00:04:18,490 --> 00:04:18,880 is where? 37 00:04:21,210 --> 00:04:22,950 Let's run it now and see the apple. 38 00:04:32,770 --> 00:04:33,310 Perfect. 39 00:04:34,780 --> 00:04:41,580 Let's take another example and how to take input from the user and match that input against the data 40 00:04:41,620 --> 00:04:42,940 we are getting from the final. 41 00:04:50,610 --> 00:04:57,600 In this script, we ask the user for his username and his password, same way we did before, and we 42 00:04:57,600 --> 00:05:01,240 check if the username and password matched the ones we get from the file. 43 00:05:01,800 --> 00:05:05,910 If they do, then we echo, they match, and then we break the loop. 44 00:05:07,680 --> 00:05:08,310 Let's run it. 45 00:05:28,060 --> 00:05:35,320 Notice, the only user and password match was the user nudniks and the password, Iola Besch, let's 46 00:05:35,320 --> 00:05:36,070 verify that. 47 00:05:39,170 --> 00:05:39,620 Here. 48 00:05:44,630 --> 00:05:48,680 We have reached the end of this lesson, please practice and see you in the next one.