1 00:00:00,270 --> 00:00:04,400 Sometimes we need a conditional that evaluates more than one expression. 2 00:00:04,400 --> 00:00:10,110 For example, maybe I want to match a range of numbers like ten through 1,000. 3 00:00:10,110 --> 00:00:11,960 We need to do two tests. 4 00:00:11,960 --> 00:00:14,940 Is the number greater than or equal to ten? 5 00:00:14,940 --> 00:00:19,170 And is the number less than or equal to 1,000? 6 00:00:19,170 --> 00:00:23,010 One way to do that is nesting two conditional statements. 7 00:00:23,010 --> 00:00:24,600 Let's take a look at how we would do that. 8 00:00:26,060 --> 00:00:28,116 Since we've already looked at these examples, 9 00:00:28,116 --> 00:00:30,330 let's comment out the rest of these conditionals. 10 00:00:34,139 --> 00:00:37,340 Now, let's go to the end of our file and add a new line. 11 00:00:38,830 --> 00:00:41,010 Let's create a new variable called num and 12 00:00:42,590 --> 00:00:46,700 set it equal to 100 then we'll add our first IF statement. 13 00:00:47,970 --> 00:00:52,290 IF num is greater than or equal to 10, then 14 00:00:56,160 --> 00:01:00,070 we can add a second nested conditional inside this conditional 15 00:01:01,100 --> 00:01:04,740 If num is less than or 16 00:01:04,740 --> 00:01:12,650 equal to 1000, now we can add the display statement. 17 00:01:15,910 --> 00:01:20,012 Your number is within the range. 18 00:01:22,813 --> 00:01:26,079 Close out our if statements and add an else. 19 00:01:30,593 --> 00:01:35,733 Your number is NOT within the range. 20 00:01:38,534 --> 00:01:43,469 Now, when we run our script, we see that your number is within the range 21 00:01:43,469 --> 00:01:47,870 because 100 is greater than 10 and less than 1,000. 22 00:01:47,870 --> 00:01:52,267 But what if we change num = 1? 23 00:01:54,001 --> 00:01:55,084 And run our script. 24 00:01:58,308 --> 00:02:01,989 We see that your number is not within the range. 25 00:02:01,989 --> 00:02:04,648 Now what happens if we change this to 10000. 26 00:02:07,978 --> 00:02:09,719 Now when we run our script, 27 00:02:09,719 --> 00:02:15,570 we get no output because it met our first condition but not our second condition. 28 00:02:15,570 --> 00:02:18,960 So we had not told our script to display anything. 29 00:02:18,960 --> 00:02:20,685 We could add a third display. 30 00:02:20,685 --> 00:02:25,920 Else echo your 31 00:02:25,920 --> 00:02:30,950 number is greater than 100. 32 00:02:30,950 --> 00:02:37,940 Not within the range. 33 00:02:37,940 --> 00:02:42,280 If we want to show a separate message based on if the number was greater than or 34 00:02:42,280 --> 00:02:45,270 less than the range this would make sense. 35 00:02:45,270 --> 00:02:49,810 We could also change our else down here to say your number 36 00:02:49,810 --> 00:02:54,440 is less than 10 not within the range. 37 00:02:55,790 --> 00:02:58,056 So now when we run our script, 38 00:02:58,056 --> 00:03:03,316 we see your number is greater than one thousand not within the range, 39 00:03:03,316 --> 00:03:08,492 and if we change our number back to one And 40 00:03:08,492 --> 00:03:13,740 run the script, we see that your number is less than 10, not within the range. 41 00:03:15,280 --> 00:03:19,870 If we want to show a single message when the number is outside the range, 42 00:03:19,870 --> 00:03:23,380 We've created duplicate code, that will make things harder to update, 43 00:03:23,380 --> 00:03:25,180 if we ever want to change this message. 44 00:03:26,400 --> 00:03:29,940 Also, nested if statements can get messy quickly, 45 00:03:29,940 --> 00:03:34,530 especially if we start writing nested statements, that are several levels deep. 46 00:03:34,530 --> 00:03:38,760 We have to remember, what conditions actually brought us to this point. 47 00:03:38,760 --> 00:03:40,760 And as we continue to indent, 48 00:03:40,760 --> 00:03:45,100 we have to start considering how our code will wrap to the next line. 49 00:03:45,100 --> 00:03:46,220 In the next video, 50 00:03:46,220 --> 00:03:49,930 I'll show you how we can use logical operators to solve these issues.