Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,330 --> 00:00:01,860
What is going on, guys?
2
00:00:01,890 --> 00:00:06,180
I hope you're doing well, getting a hold of all the new concepts.
3
00:00:06,210 --> 00:00:13,110
We are learning in this chorus and in this video we are going to move even a step further with the control
4
00:00:13,110 --> 00:00:14,220
flow topic.
5
00:00:14,340 --> 00:00:17,370
So let's, first of all, review what we've done so far.
6
00:00:17,490 --> 00:00:23,880
We used the basic live condition and based on its result, which was true or false.
7
00:00:24,220 --> 00:00:29,190
We've executed some associated commands depending on the result of the condition.
8
00:00:29,490 --> 00:00:31,050
You do remember that, right?
9
00:00:31,170 --> 00:00:37,660
And we've seen a couple of examples, like when we wanted to find out what is the maximum value and
10
00:00:37,670 --> 00:00:39,810
wanted to give a number is number one.
11
00:00:39,810 --> 00:00:43,980
And number two, we asked if no one was greater than number two.
12
00:00:44,280 --> 00:00:50,520
And if that's the case, if the result of this condition is true, we would have printed that the maximum
13
00:00:50,580 --> 00:00:51,720
is number one.
14
00:00:51,930 --> 00:00:54,290
Otherwise, we would have printed on.
15
00:00:54,300 --> 00:00:54,660
Right.
16
00:00:54,690 --> 00:01:00,660
Otherwise, if the result of the condition was false, we would have printed the maximum is number two.
17
00:01:00,810 --> 00:01:08,250
So we basically will run different commands, different parts of code based on the result of a given
18
00:01:08,250 --> 00:01:08,790
condition.
19
00:01:09,030 --> 00:01:16,200
And also, we've seen an example where we tested out if a number forgiven number was even or odd.
20
00:01:16,590 --> 00:01:18,060
We've seen how to test it.
21
00:01:18,120 --> 00:01:24,420
We simply checked with the remainder of the division by two will be either a one or a zero.
22
00:01:24,840 --> 00:01:28,260
And then based on the result we printed out.
23
00:01:28,290 --> 00:01:30,160
If the number is even poorer.
24
00:01:30,210 --> 00:01:31,530
The number was odd.
25
00:01:31,650 --> 00:01:32,220
All right.
26
00:01:32,250 --> 00:01:37,530
So I hope you got the whole idea of this, because it's very important that you didn't miss anything
27
00:01:37,560 --> 00:01:38,820
that we said previously.
28
00:01:39,120 --> 00:01:41,220
It was just a reminder for you guys.
29
00:01:41,580 --> 00:01:43,200
Before we move on.
30
00:01:43,350 --> 00:01:43,740
Right.
31
00:01:43,840 --> 00:01:46,830
We moving forward in these control flow topic.
32
00:01:47,400 --> 00:01:51,450
So now what I want us to do is to take a look at the following example.
33
00:01:51,540 --> 00:01:55,530
So let's take a look at this exercise and it goes like this.
34
00:01:55,830 --> 00:01:59,010
First of all, get a grade from the user.
35
00:01:59,130 --> 00:01:59,570
All right.
36
00:01:59,580 --> 00:02:01,660
Once again, get the users grade.
37
00:02:01,860 --> 00:02:05,340
And if the grade is 80 or higher, we will print.
38
00:02:05,430 --> 00:02:06,980
Excellent job message.
39
00:02:07,170 --> 00:02:12,390
Otherwise, if the grade is not 80 or higher, meaning it's less than 80.
40
00:02:12,750 --> 00:02:16,500
But yet it may be 60 or higher.
41
00:02:16,860 --> 00:02:21,180
We will print not bad, but study a little bit more next time.
42
00:02:21,180 --> 00:02:25,260
Message or write any of the grade is less than 60.
43
00:02:25,350 --> 00:02:28,890
Meaning the two previous conditions didn't was not.
44
00:02:28,890 --> 00:02:30,300
We're not satisfied.
45
00:02:30,750 --> 00:02:32,520
We will print the following message.
46
00:02:32,880 --> 00:02:35,970
Oh, you didn't pass something like that.
47
00:02:36,060 --> 00:02:37,650
Try again next time.
48
00:02:37,770 --> 00:02:38,220
All right.
49
00:02:38,250 --> 00:02:39,900
Do your best for the next exam.
50
00:02:40,860 --> 00:02:48,540
So if you take a closer look at this exercise and you can see basically that a simple if el statement,
51
00:02:48,870 --> 00:02:54,030
just as we used previously, he's just not going to be enough in this case.
52
00:02:54,510 --> 00:02:58,840
We've used here some more or let's say modified approach.
53
00:02:58,890 --> 00:03:03,930
The LC approach, which is also sometimes called a nested condition.
54
00:03:04,320 --> 00:03:07,700
And the reason for that is because we nest.
55
00:03:07,890 --> 00:03:09,960
One condition into the other.
56
00:03:10,280 --> 00:03:15,720
And let's see basically how it looks like the first condition was if Grady's 80 or higher.
57
00:03:16,200 --> 00:03:24,300
And then the else of this result, meaning the grade maybe probably is less than 80.
58
00:03:24,510 --> 00:03:31,620
But we still use the else if statement and we checked out if the grade, maybe it's less than 80.
59
00:03:31,650 --> 00:03:34,590
But it still may be 60 or higher.
60
00:03:34,710 --> 00:03:35,190
All right.
61
00:03:35,310 --> 00:03:41,670
And if that's also not the case, then we are moving to the third through the force option in this case.
62
00:03:42,000 --> 00:03:45,450
When we have the grade less than 60.
63
00:03:45,540 --> 00:03:46,890
So just to make it clear.
64
00:03:46,980 --> 00:03:51,150
Let's go over the flow once again, step by step.
65
00:03:51,320 --> 00:03:51,720
All right.
66
00:03:51,840 --> 00:03:53,850
So we got our great input.
67
00:03:54,000 --> 00:03:55,200
That's the first step.
68
00:03:55,500 --> 00:03:57,630
Get the grade from the user.
69
00:03:58,320 --> 00:04:04,770
Now we use the condition to see if the test was good and if the grade is 80 or higher.
70
00:04:04,830 --> 00:04:05,340
All right.
71
00:04:05,400 --> 00:04:06,990
If grade is 80 or higher.
72
00:04:07,260 --> 00:04:08,610
This is our condition.
73
00:04:08,640 --> 00:04:12,510
This case is the result of this particular condition is true.
74
00:04:12,870 --> 00:04:18,070
Then let's simply print some congratulations message and print to the user.
75
00:04:18,090 --> 00:04:19,580
Some excellent job.
76
00:04:19,590 --> 00:04:21,660
You've done great on your last exam.
77
00:04:21,900 --> 00:04:22,350
All right.
78
00:04:22,500 --> 00:04:23,410
But if the resolved.
79
00:04:23,410 --> 00:04:24,720
This is not true.
80
00:04:24,840 --> 00:04:28,440
Which leaves us with the fact that the result is false.
81
00:04:28,860 --> 00:04:34,950
And now, at this point, as opposed to two different examples we've seen so far, we would like to
82
00:04:34,950 --> 00:04:37,980
use another condition, a nested condition.
83
00:04:38,190 --> 00:04:44,340
So we use the following condition to ask if grade is 60 or higher, maybe maybe 60 or higher.
84
00:04:44,370 --> 00:04:44,700
Right.
85
00:04:44,730 --> 00:04:45,690
It makes sense.
86
00:04:45,840 --> 00:04:48,180
And we want to know if that's the case.
87
00:04:48,630 --> 00:04:55,200
So we know that at this point, the grade is definitely less than 80, but now it can be in the range
88
00:04:55,200 --> 00:04:58,730
between 60 to 80 or less than 60.
89
00:04:58,840 --> 00:05:00,960
That's exactly what we want to find out.
90
00:05:01,540 --> 00:05:07,920
And we want two different messages to different messages I'm sorry, printed for these two options.
91
00:05:08,100 --> 00:05:14,430
So if the result of this condition is true, then we know that the grade is between 60 to 80.
92
00:05:14,760 --> 00:05:19,740
And although that's not the best grade year that you can get on your exam.
93
00:05:20,100 --> 00:05:21,330
That's not so bad.
94
00:05:21,330 --> 00:05:21,750
Right.
95
00:05:22,080 --> 00:05:25,950
So in this case, we would like to print not bad message.
96
00:05:26,040 --> 00:05:28,830
And you've done you've done pretty well.
97
00:05:28,950 --> 00:05:29,430
Not bad.
98
00:05:29,790 --> 00:05:36,960
And otherwise, if the result of this condition happens also to be false, then we can definitely say
99
00:05:37,710 --> 00:05:39,720
that the grade is less than 80.
100
00:05:39,990 --> 00:05:42,480
And also it's less than 60.
101
00:05:42,930 --> 00:05:50,790
So we will have to print a failed try again message and ask the user to give to give that another shot,
102
00:05:50,790 --> 00:05:52,500
to give another shot at the exam.
103
00:05:52,860 --> 00:05:55,200
So hopefully he will pass next time.
104
00:05:55,320 --> 00:05:57,900
And that would basically be it, guys.
105
00:05:57,930 --> 00:06:01,800
And that's how you use nested conditions in programming.
106
00:06:02,250 --> 00:06:07,290
And you can embed them at any stage you like as many times as you like.
107
00:06:07,410 --> 00:06:12,720
Just make sure that these whole structure makes sense.
108
00:06:12,750 --> 00:06:13,260
All right.
109
00:06:13,450 --> 00:06:21,810
And now, once we've mapped every sentence to these representation on the left, this graphical representation
110
00:06:21,810 --> 00:06:22,410
on the left.
111
00:06:22,770 --> 00:06:28,650
I want us to take a deeper look and see how it can be done in our programming language.
112
00:06:28,800 --> 00:06:30,080
So let's take a look.
9693
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.