1 00:00:00,600 --> 00:00:02,140 Hello and welcome. 2 00:00:02,190 --> 00:00:13,530 In this video be introducing you to conditionals conditionals are called structures which allow you 3 00:00:14,040 --> 00:00:23,040 to test if an expression or a condition returns true or not. 4 00:00:23,400 --> 00:00:31,670 They are used to perform different actions based on different conditions. 5 00:00:32,050 --> 00:00:42,630 The common condition conditional statements are an if statement basically an if statement is used to 6 00:00:42,660 --> 00:00:51,890 specify a block of code that will be executed if specified condition is true. 7 00:00:52,260 --> 00:01:04,260 We also have an else statement basically that checks the condition that is set within the if statement 8 00:01:04,920 --> 00:01:08,210 is true or false that is false. 9 00:01:08,430 --> 00:01:14,660 Then the code inside the else block will execute. 10 00:01:14,660 --> 00:01:15,300 So the. 11 00:01:15,300 --> 00:01:24,140 Else dead men will only come into effect if the conditions set within the if statement returns force. 12 00:01:24,150 --> 00:01:31,810 So in my console I have called a variable here that I have defined call my number and I've given a value 13 00:01:31,830 --> 00:01:41,810 of seven and a muse in an IF statement which is a conditional statement to test a condition so check 14 00:01:41,930 --> 00:01:51,070 in if the variable called my name is equal to 7. 15 00:01:51,070 --> 00:01:56,600 If it is the code this code here will be executed. 16 00:01:56,610 --> 00:01:58,730 Which is answered a lot. 17 00:01:58,760 --> 00:02:03,240 This means it will print out this message inside this console. 18 00:02:03,230 --> 00:02:05,240 It will say look 7. 19 00:02:05,490 --> 00:02:12,060 If the condition is true but the condition is condition is definitely true because a variable has a 20 00:02:12,060 --> 00:02:13,820 value of 7. 21 00:02:13,920 --> 00:02:15,300 I'm just checking here. 22 00:02:15,300 --> 00:02:16,620 This is the condition. 23 00:02:16,940 --> 00:02:20,560 The expression inside that if. 24 00:02:20,910 --> 00:02:21,570 Which is this. 25 00:02:21,570 --> 00:02:23,760 Here is the test. 26 00:02:23,880 --> 00:02:35,370 Okay so this uses the identity operator which is post to here to compare the value to compare this value. 27 00:02:35,370 --> 00:02:39,030 Here is 7 it is equal to 7. 28 00:02:39,030 --> 00:02:41,450 If it is it will print out that. 29 00:02:41,460 --> 00:02:47,370 So I'm just going to press enter and it all print out is 7 in the cons.. 30 00:02:47,550 --> 00:02:50,510 So in this case the condition is true. 31 00:02:50,700 --> 00:02:54,780 So no other code needs to be executed. 32 00:02:54,780 --> 00:03:05,040 However you can also create a condition in which you add an else statement so that the condition inside 33 00:03:05,040 --> 00:03:14,400 the IF statement is wrong then a different block of code will execute which is located inside the elfs 34 00:03:14,700 --> 00:03:15,850 block. 35 00:03:16,440 --> 00:03:19,320 So here I've got another variable same chord. 36 00:03:19,320 --> 00:03:22,210 My numbers have changed the value to 10. 37 00:03:22,470 --> 00:03:26,850 And here I have included two statements. 38 00:03:26,970 --> 00:03:29,910 The if statement and the L statement. 39 00:03:29,940 --> 00:03:34,070 So what happens is the comparison is made. 40 00:03:34,080 --> 00:03:38,220 The condition is tested and the test is a side. 41 00:03:38,280 --> 00:03:42,790 If blockin said here so is testin If this variable. 42 00:03:42,810 --> 00:03:45,410 My number is equal to 7. 43 00:03:45,510 --> 00:03:49,300 This will return force because the value is 10. 44 00:03:49,440 --> 00:03:51,790 So what happened this block of code here. 45 00:03:51,810 --> 00:04:00,570 That said lock is 7 will not run so it will not get executed because the value is wrong. 46 00:04:00,570 --> 00:04:01,770 So what happens. 47 00:04:01,770 --> 00:04:10,060 It will skip the block and it will execute this code because this condition in siby if this wrong he 48 00:04:10,050 --> 00:04:12,600 doesn't value it to 10. 49 00:04:12,630 --> 00:04:20,190 So once a comparison has been made it all run code that matches the comparison. 50 00:04:20,190 --> 00:04:26,360 So in this case the code inside the comparison is made inside the block. 51 00:04:26,520 --> 00:04:33,620 So is testing the condition to condition as test to force because the value segment is not the 7. 52 00:04:33,900 --> 00:04:39,740 So is now close to 10 so the block of code here says because 7 will not run. 53 00:04:39,810 --> 00:04:45,380 Instead it will run this inside the console in the way you see cancelled on log. 54 00:04:45,620 --> 00:04:54,150 Means is going to print a message inside the console so 5 press enter it can see your not very lucky 55 00:04:54,150 --> 00:04:59,880 today because this condition that were tested did not evaluate to true. 56 00:05:00,410 --> 00:05:04,080 So this quote here is executed debt. 57 00:05:04,130 --> 00:05:13,010 So in a very simple example here to a lost trade how conditional statement works so there are other 58 00:05:13,010 --> 00:05:19,270 types of conditional statement but the very basic is if the else statement. 59 00:05:19,430 --> 00:05:27,140 So the key thing to note here is in the if else statement this The condition to be tested or the expression 60 00:05:27,170 --> 00:05:31,490 to be tested is always located in the block. 61 00:05:31,520 --> 00:05:33,680 So that's where you set the condition. 62 00:05:33,680 --> 00:05:35,900 You can see how have set the condition here. 63 00:05:36,260 --> 00:05:43,100 So if that condition does not evaluate to be true then the block of code inside the IF statement is 64 00:05:43,100 --> 00:05:47,440 skipped the one in the else block is executed. 65 00:05:47,630 --> 00:05:54,400 So in between the curly braces the opening calibrators And that's the closing calibrators is where you're 66 00:05:54,400 --> 00:05:57,310 right the block of code that will execute. 67 00:05:57,310 --> 00:06:04,400 You can see here this is the block for the here and in the elthorne you've got the opening curly braces 68 00:06:04,840 --> 00:06:10,780 and the closing calibrators and in between you you've got the code block that executes. 69 00:06:10,860 --> 00:06:17,350 If a condition within the if statement or if block is wrong. 70 00:06:17,540 --> 00:06:18,440 So that's it. 71 00:06:18,440 --> 00:06:19,580 I hope it makes sense. 72 00:06:19,580 --> 00:06:21,590 If not please let me know. 73 00:06:21,830 --> 00:06:23,720 Thank you and bye for now.