Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,090 --> 00:00:01,570
What is going on, guys?
2
00:00:01,590 --> 00:00:08,010
And now that you are familiar with what are conditions and what they are used for, let's see how we
3
00:00:08,010 --> 00:00:12,180
can use them and implement them in C programming language.
4
00:00:12,390 --> 00:00:18,150
Let's start with our previous congratulations example, where we have to get a grade as an input.
5
00:00:18,600 --> 00:00:25,010
And if these grade equals or higher than 60, then we just printed out congratulations.
6
00:00:25,500 --> 00:00:28,300
Otherwise printed out a field.
7
00:00:28,350 --> 00:00:29,500
Try again, Masad.
8
00:00:29,640 --> 00:00:36,390
And if we know that we write these programming C language, let's first of all start with our well-known
9
00:00:36,420 --> 00:00:37,200
pirates.
10
00:00:37,530 --> 00:00:42,810
So let's use the includes include SDD, TDA, old age and include SDD Liebe.
11
00:00:42,990 --> 00:00:49,920
These are basically the two default included that we've seen in code blocks in our code examples in
12
00:00:49,920 --> 00:00:51,120
the previous videos.
13
00:00:51,300 --> 00:00:54,650
And now we also know that we need some starting point.
14
00:00:54,660 --> 00:00:55,110
Right.
15
00:00:55,140 --> 00:00:58,840
Perhaps we can also write these main thing.
16
00:00:58,950 --> 00:01:04,620
Already there int Main and the curly brackets to hold the block of commands.
17
00:01:04,800 --> 00:01:05,400
Great.
18
00:01:05,610 --> 00:01:09,720
And now we know that we have to get the grade as an input from the user.
19
00:01:10,020 --> 00:01:14,150
So let's first of all declare these variable use in to grade.
20
00:01:14,160 --> 00:01:16,960
We created a variable called the gradient.
21
00:01:17,100 --> 00:01:19,080
And these of type end.
22
00:01:19,260 --> 00:01:26,880
And then we will simply read the value from the user using scan F and hold this value inside of these
23
00:01:26,880 --> 00:01:27,570
variable.
24
00:01:27,840 --> 00:01:32,730
And up until now, everything seems to be as usual and write nothing new.
25
00:01:32,910 --> 00:01:35,640
So I think that's the time we should add the condition.
26
00:01:36,000 --> 00:01:37,980
And actually, that's pretty simple.
27
00:01:37,980 --> 00:01:45,360
We just write the EEF statement and after war, as we specify the condition in the parentheses.
28
00:01:45,510 --> 00:01:51,250
So the condition in this case is simply if greyed equals or higher than 60.
29
00:01:51,450 --> 00:01:58,530
And now we can specify the commands that should be executed once the condition happens to be true.
30
00:01:58,710 --> 00:02:05,220
So in this case, we should simply use the printf command to just display a congratulations message
31
00:02:05,220 --> 00:02:05,850
on the screen.
32
00:02:06,270 --> 00:02:10,520
If the grade is actually higher or equals to 60.
33
00:02:10,740 --> 00:02:12,630
So that's all good and nice.
34
00:02:12,690 --> 00:02:20,250
And if we currently build an R&D program there, this program will be just capable of printing.
35
00:02:20,790 --> 00:02:21,750
Congratulations.
36
00:02:21,750 --> 00:02:25,470
Message only is the result of the condition is true.
37
00:02:25,860 --> 00:02:28,110
If the result of the condition is false.
38
00:02:28,230 --> 00:02:28,710
All right.
39
00:02:28,740 --> 00:02:31,110
So basically nothing will happen here.
40
00:02:31,470 --> 00:02:35,100
The program just will read that the value from the user.
41
00:02:35,400 --> 00:02:37,860
But it will not print anything to the screen.
42
00:02:38,100 --> 00:02:40,620
You may try to ram this code at home.
43
00:02:40,740 --> 00:02:45,190
Simply enter, I dunno, 50 and see what happens in the.
44
00:02:45,190 --> 00:02:48,180
You probably will see that nothing will happen.
45
00:02:48,300 --> 00:02:56,400
So that's why you would like to specify in the condition itself what commands should be executed if
46
00:02:56,400 --> 00:02:59,160
the result of the condition is false.
47
00:02:59,190 --> 00:02:59,460
Right.
48
00:02:59,490 --> 00:03:03,060
We have here what will happen if the result is true.
49
00:03:03,160 --> 00:03:05,490
If the if the result of the condition is true.
50
00:03:06,000 --> 00:03:10,590
We also want to specify what will happen if the result of the condition is false.
51
00:03:10,740 --> 00:03:11,850
So how can we do it?
52
00:03:11,880 --> 00:03:13,490
How can we print the field?
53
00:03:13,560 --> 00:03:14,160
Try again.
54
00:03:14,160 --> 00:03:15,270
Message to the screen.
55
00:03:15,570 --> 00:03:21,630
If the condition is false, it simply should add the else section, meaning all the commands that will
56
00:03:21,630 --> 00:03:25,500
happen if the grade is less than 60.
57
00:03:25,680 --> 00:03:29,160
So then you will just print fail, try again.
58
00:03:29,580 --> 00:03:30,840
And there you go.
59
00:03:31,020 --> 00:03:33,660
And actually, that's pretty simple, right?
60
00:03:33,690 --> 00:03:34,800
Nothing complicated.
61
00:03:34,800 --> 00:03:40,110
Just an F and a bunch of commands and that may be executed based on the result.
62
00:03:40,140 --> 00:03:47,670
If it's true and an ls the some other commands that that may be executed if the result of the condition
63
00:03:47,670 --> 00:03:48,510
is false.
64
00:03:48,690 --> 00:03:54,930
So now I want us to get over this code line by line and make sure that we fully understand its flow,
65
00:03:55,110 --> 00:04:02,940
meaning what lines are going to be executed before and after and simply how the the program that your
66
00:04:02,940 --> 00:04:05,790
computer is going to execute these code.
67
00:04:05,880 --> 00:04:06,800
And before you finish.
68
00:04:06,870 --> 00:04:14,580
Just don't forget to add the return zero at the end to specifying that there that the program has been
69
00:04:14,580 --> 00:04:15,240
terminated.
70
00:04:15,240 --> 00:04:15,790
Successful.
71
00:04:15,900 --> 00:04:16,410
All right.
72
00:04:16,440 --> 00:04:18,480
So the steps are as follows.
73
00:04:18,540 --> 00:04:21,180
We, first of all, start in the main block.
74
00:04:21,600 --> 00:04:25,380
Then we declare our first variable, the integrated.
75
00:04:26,070 --> 00:04:30,230
Then we read the value from the user by using the scanner function.
76
00:04:30,330 --> 00:04:36,380
And let's say that the value in this case was, I don't know, something like 90.
77
00:04:36,570 --> 00:04:38,850
And now we should just use the condition.
78
00:04:38,880 --> 00:04:45,750
And ask QIf grade is greater or equals to 60, which happens to be true.
79
00:04:46,110 --> 00:04:50,850
And if that's the case, we print that congratulations message to the screen.
80
00:04:50,970 --> 00:04:57,450
And then, of course, we skip the LS part because it should only be executed when the condition is
81
00:04:57,450 --> 00:04:58,230
false.
82
00:04:58,290 --> 00:04:59,210
Which is not the.
83
00:04:59,290 --> 00:05:02,620
Case, and you just returned the zero.
84
00:05:02,650 --> 00:05:04,120
And there you go.
85
00:05:04,300 --> 00:05:13,570
That was basically the flow for how your computer will execute this code line by line if the grade received
86
00:05:13,690 --> 00:05:18,010
from the usery will equal to 90 in this case.
87
00:05:18,190 --> 00:05:20,860
And now let's take a look at the flow of the program.
88
00:05:20,950 --> 00:05:25,690
When we receive a grade that is actually less than 60.
89
00:05:25,840 --> 00:05:28,390
So you create a variable as previously.
90
00:05:28,780 --> 00:05:36,040
And then you read the value of the grade, which in this case, we assume that it will be just fifty,
91
00:05:36,040 --> 00:05:36,670
let's say.
92
00:05:36,820 --> 00:05:41,890
And then you come to the conditions section, which in this case happens to be false.
93
00:05:41,920 --> 00:05:42,280
Right.
94
00:05:42,700 --> 00:05:45,700
Fifty is not greater than 60.
95
00:05:45,850 --> 00:05:48,970
So if it's not true, you don't run the print.
96
00:05:49,000 --> 00:05:50,040
Congratulations.
97
00:05:50,050 --> 00:05:51,400
Message through the screen.
98
00:05:51,760 --> 00:05:53,980
You simply move to the yellow section.
99
00:05:54,130 --> 00:05:57,040
And now you execute the commands of the else block.
100
00:05:57,160 --> 00:05:58,690
You simply print failed.
101
00:05:58,780 --> 00:06:00,220
Try again message.
102
00:06:00,400 --> 00:06:02,870
Then you move on to the return zero.
103
00:06:02,890 --> 00:06:04,030
And there you go.
104
00:06:04,030 --> 00:06:05,680
Your program is complete.
105
00:06:05,770 --> 00:06:13,580
So that basically was, guys, the second flow of how the computer will Iran this code.
106
00:06:14,170 --> 00:06:19,240
If a given grade from the user is actually less than 60.
107
00:06:19,360 --> 00:06:21,100
So we will not run.
108
00:06:21,110 --> 00:06:24,040
It will not execute the code under the EEF section.
109
00:06:24,310 --> 00:06:30,310
It will simply go to the else and just execute the print command stated there.
110
00:06:30,430 --> 00:06:35,350
So, no, you know, the flow of your code when using control flow mechanism.
111
00:06:35,710 --> 00:06:37,740
It's a very important concept, guys.
112
00:06:37,840 --> 00:06:45,490
And I'm glad that now you know, the general concept as well as how it is being executed and implemented
113
00:06:45,700 --> 00:06:47,830
in C programming language.
114
00:06:48,040 --> 00:06:49,780
I wish you good luck in this section.
115
00:06:49,870 --> 00:06:52,420
And I'll see you in the next video by.
10107
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.