WEBVTT 00:01.460 --> 00:02.930 Welcome to the second step. 00:04.080 --> 00:09.420 In this step, you're going to learn about each statement and the condition expressions, and in the 00:09.420 --> 00:12.810 end, I'll show you a few example projects using the if statement. 00:13.260 --> 00:14.010 Let's get started. 00:14.790 --> 00:16.080 Let's take a look at an example. 00:16.080 --> 00:21.720 If statements, let's say that you have a program that prints messages depending on a basketball game, 00:21.720 --> 00:28.650 play racecar, for example, if the score is higher than three, then it will say, good, let's create 00:28.650 --> 00:30.690 the if portion of that program. 00:30.720 --> 00:33.960 Now, I'm going to show you the whole program afterwards. 00:33.960 --> 00:36.140 But for now, let's focus on the incident. 00:36.180 --> 00:37.980 OK, now I'm going to type if. 00:39.330 --> 00:42.840 Then I'm going to wrap the conditioned part in the parentheses like this. 00:43.890 --> 00:48.240 Then I'm going to type scar greater than three using a combination operator. 00:49.360 --> 00:54.970 If statement has its own block, its own scope, by the way, so I'm going to create a new blog now. 00:56.080 --> 00:59.020 Then inside the blog, I'm going to type the good message. 01:00.110 --> 01:05.540 If the score is higher than three, then it will bring good to the council, so far, so good. 01:05.840 --> 01:08.150 However, something is missing, isn't it? 01:08.870 --> 01:09.440 Yes. 01:09.620 --> 01:13.720 Engo You can type an if statement like this, but you don't have to. 01:14.210 --> 01:15.490 Let me show you what I mean. 01:17.290 --> 01:24.970 But right, I removed the parentheses, unlike C based languages Engo, you don't have to type dependencies 01:24.970 --> 01:26.180 unless you really need to. 01:26.410 --> 01:28.660 This version is more concise, isn't it? 01:29.290 --> 01:32.500 This statement is exactly the same as the previous one. 01:33.130 --> 01:36.220 Now, let's take a look at the parts of this statement. 01:37.500 --> 01:43.430 This part is the if statements blog, you know, what's a block, so I won't explain to you again, 01:43.650 --> 01:46.680 just remember that a block creates its own scope. 01:46.950 --> 01:53.040 So any declared names inside this F block won't be accessible by the outer blocks. 01:53.370 --> 01:57.060 But if block itself and the following branches. 01:57.960 --> 02:00.010 You'll learn what I mean by the branches soon. 02:00.180 --> 02:00.870 No worries. 02:01.200 --> 02:02.480 All right, let's continue. 02:04.830 --> 02:10.900 This is a condition expression of the if statement, this expression should always yield a bool value. 02:11.280 --> 02:13.550 You already know what a bull expression is, right? 02:13.920 --> 02:17.400 So you can use any bull expression or a bull value here. 02:19.520 --> 02:26.210 His, you know, goal type system is unlike other sea based languages, so you can't use in other value 02:26.210 --> 02:32.900 than Abu in JavaScript, for example, you can put any value in a condition expression and it will work, 02:32.900 --> 02:33.660 but not in. 02:35.120 --> 02:38.090 Check out the example that I've created for you to show you this. 02:38.270 --> 02:39.440 It's in the resources. 02:40.450 --> 02:46.540 OK, these were the parts of this statement that are simple right now, let's talk a little bit more 02:46.540 --> 02:48.520 about this condition expression. 02:50.260 --> 02:56.630 They say that your program also evaluates whether a score is a valid one or not to do that here. 02:56.650 --> 03:00.550 I'm going to use another expression with a logical and operator like this. 03:01.340 --> 03:05.530 As you can see, the condition expression still yields value, right? 03:06.540 --> 03:12.360 To combine these two expressions together, I've used a logical and operator that you've seen before. 03:13.400 --> 03:18.950 Now, it only execute the if statements block if the score is higher than three and only if it's also 03:18.950 --> 03:19.720 a valid score. 03:20.150 --> 03:25.790 OK, by the way, sometimes I see code like this, which is written by beginners here. 03:25.790 --> 03:28.730 It's clear that that valid variables type is a ball. 03:28.940 --> 03:29.330 Right. 03:30.140 --> 03:32.840 Or I couldn't have compared it with a true value here. 03:33.420 --> 03:35.720 If so, then you don't need to type it like this. 03:36.020 --> 03:36.710 Let's check it out. 03:38.890 --> 03:40.060 This is better, isn't it? 03:40.330 --> 03:45.890 As you can see, I'm directly using the valid variable here so you can use bool values directly. 03:46.000 --> 03:47.320 You don't have to compare the. 03:48.290 --> 03:53.330 By the way, let's say that you want to print the message only for the invalid's course, how can you 03:53.330 --> 03:53.810 do that? 03:54.250 --> 03:54.940 Let's check it out. 03:56.770 --> 03:58.450 Here are used the not operator. 03:58.990 --> 04:04.540 So now if statements blog will only run when the score is higher than three and only one if it's not 04:04.540 --> 04:05.260 a valid score. 04:06.610 --> 04:10.030 OK, now let's put this in a program context to understand better. 04:12.750 --> 04:13.300 OK, good. 04:13.590 --> 04:17.100 Now let's short declare score and valid variables like this. 04:18.130 --> 04:21.670 Let's say that the player's score is five and it's a valid score. 04:22.630 --> 04:25.190 So let's initialize the variables with those values. 04:25.210 --> 04:25.450 Now. 04:26.360 --> 04:27.170 OK, let's run its. 04:30.080 --> 04:35.540 It brings good message into the console is because, as I said, the score is higher than three and 04:35.540 --> 04:36.170 it is worth it. 04:36.890 --> 04:38.660 Now let's change those variables. 04:39.990 --> 04:42.660 They say that the player score is three this time. 04:43.990 --> 04:45.240 OK, now let's try it again. 04:48.780 --> 04:54.870 As you can see this time, it doesn't print anything since the score was less than three, so if statements 04:54.870 --> 04:56.640 condition hasn't been executed. 04:58.000 --> 05:03.220 OK, now let's say that you want to print another message and the score is equal and less than three. 05:04.140 --> 05:09.840 To do that, you need to use an asset class in the next lecture, I'm going to show you how to do that. 05:10.110 --> 05:10.950 So see you there.