1
00:00:00,300 --> 00:00:00,720
OK.

2
00:00:00,750 --> 00:00:02,310
Welcome back to another lecture.

3
00:00:02,730 --> 00:00:12,750
So in the previous lecture, we went over kind of the theory behind logic and using some Boolean.

4
00:00:13,770 --> 00:00:22,590
We talked a little bit about truth tables and we kind of introduced one tiny part of what conditional

5
00:00:22,590 --> 00:00:26,700
statements are in C++ and just programming in general.

6
00:00:27,090 --> 00:00:35,100
You notice in the last lecture we use that word, if that is a conditional statement, part of a conditional

7
00:00:35,100 --> 00:00:35,580
statement.

8
00:00:36,570 --> 00:00:41,610
So in this lecture, we're going to be going over kind of how to implement all this in code.

9
00:00:42,720 --> 00:00:49,320
So we will be going over Boolean and code, which you've already kind of had a little bit of an introduction

10
00:00:49,320 --> 00:00:49,770
to.

11
00:00:49,920 --> 00:00:57,690
But we'll be using billions to satisfy conditional statements that can be evaluated to true or false.

12
00:00:58,620 --> 00:01:05,520
And we will be also looking at various operators that we can use inside of conditional statements.

13
00:01:07,040 --> 00:01:10,100
And we'll be looking at those keywords as well, like the if.

14
00:01:10,430 --> 00:01:14,270
And there's also some other ones that we'll be using, like ealth and elusive.

15
00:01:15,390 --> 00:01:22,500
So with that, let's go ahead and get started, so I'm definitely going to want to print some stuff

16
00:01:22,500 --> 00:01:24,690
out to the console here.

17
00:01:25,530 --> 00:01:30,840
So you notice I have a terminal open PowerShell terminal.

18
00:01:31,470 --> 00:01:35,330
I've also already made a file conditional star copy.

19
00:01:35,340 --> 00:01:40,740
I just put it in this first program directory, even though it's not our first program and went ahead

20
00:01:40,740 --> 00:01:41,520
and left it in there.

21
00:01:41,520 --> 00:01:47,070
So if you do not have a file update, go ahead to file and make a new file.

22
00:01:47,580 --> 00:01:55,050
And if you don't have a terminal going and you need to compile your code in a terminal, then you can

23
00:01:55,050 --> 00:01:57,390
go up here to terminal and the terminal.

24
00:01:59,750 --> 00:02:05,510
And like I said in some of these lectures, I'm going to be using Visual Studio similar lectures, I

25
00:02:05,510 --> 00:02:11,060
will be using Sea Lion and sometimes I'll just be using text editor like them.

26
00:02:11,390 --> 00:02:13,940
So in the command prompt or just this poem?

27
00:02:15,560 --> 00:02:15,820
All right.

28
00:02:15,830 --> 00:02:17,360
So let's go ahead and get started.

29
00:02:17,390 --> 00:02:24,780
Like I said, I want stuff to print out to the console, so I'm going to include Io stream here.

30
00:02:26,330 --> 00:02:34,850
I'll do the standard using namespace and I want you into main and make it main function here.

31
00:02:37,370 --> 00:02:43,400
So the first thing that I'm going to do is make some variables and those variables are going to be Boolean

32
00:02:43,410 --> 00:02:49,340
to start off with, so I'm going to make a Boolean and I'm just going to call it be one.

33
00:02:50,360 --> 00:02:52,070
I'm going to set that to true.

34
00:02:52,080 --> 00:02:57,560
I'm going to make another Boolean and call it B to set that to be false.

35
00:02:58,700 --> 00:03:08,120
I also will go ahead and define some integers here so I can use them and compare them and some of our

36
00:03:08,120 --> 00:03:09,380
conditional statements.

37
00:03:10,100 --> 00:03:14,090
So I'm going to make an integer, and I just call this i1.

38
00:03:14,840 --> 00:03:16,280
I'll make you do it five.

39
00:03:17,390 --> 00:03:23,060
And I'll say and and I to and I'll make this equal to 10.

40
00:03:26,390 --> 00:03:26,810
OK.

41
00:03:27,230 --> 00:03:35,120
So the first thing that I want to do is kind of go over some of the operators that we can use in C++

42
00:03:35,960 --> 00:03:43,190
and what we're talking about today is going to be the logical operators.

43
00:03:44,650 --> 00:03:48,040
Operators are something like many you see out.

44
00:03:48,970 --> 00:03:50,680
Remember, I have to put these.

45
00:03:52,200 --> 00:03:53,650
Two things right here.

46
00:03:54,480 --> 00:04:00,130
So this is that output or also known as the insertion operator.

47
00:04:00,810 --> 00:04:05,010
Remember that I was kind of saying that what happens is whatever you put on the right side of it, it

48
00:04:05,010 --> 00:04:10,800
kind of goes into these open open mouth and then goes out to the console out right here.

49
00:04:11,520 --> 00:04:12,840
So this is an operator.

50
00:04:13,230 --> 00:04:19,890
Another operator that you've already seen is the assignment operator, which is this singular equals

51
00:04:19,890 --> 00:04:25,320
sign here that assigns the value on the right side of the operator to the variable on the left side

52
00:04:25,320 --> 00:04:25,980
of the operator.

53
00:04:27,680 --> 00:04:34,130
So we're going to be talking about some more operators, and those are going to be things like.

54
00:04:35,190 --> 00:04:36,510
Two equal signs.

55
00:04:38,100 --> 00:04:38,730
And.

56
00:04:40,040 --> 00:04:51,860
Two of these pipes to ampersand, and we'll also have something like a greater than or greater than

57
00:04:51,880 --> 00:04:56,620
and less than greater than or equal to less than or equal to.

58
00:04:58,040 --> 00:04:59,660
So we have all of these right here.

59
00:05:01,190 --> 00:05:05,960
So let's go ahead and start out with this one right here.

60
00:05:07,210 --> 00:05:09,090
So this is two equal signs.

61
00:05:09,100 --> 00:05:11,290
So what does this mean?

62
00:05:11,320 --> 00:05:13,330
We already have seen one equals sign.

63
00:05:13,570 --> 00:05:14,920
Well, this one equals sign.

64
00:05:14,920 --> 00:05:20,080
Like we already said, it's only used for assignment, so take whatever is on the right side of it and

65
00:05:20,080 --> 00:05:21,940
put it in the variable to the left.

66
00:05:23,520 --> 00:05:29,760
The equals sign is for actual equality when you want to check whether something is equal to something

67
00:05:29,760 --> 00:05:31,560
else, whether they're the same thing.

68
00:05:33,240 --> 00:05:43,440
So that would be, you know, something like five equals five, you know, seven equals seven.

69
00:05:43,920 --> 00:05:45,000
Things like that.

70
00:05:47,930 --> 00:05:57,260
Another thing that I can add in here is when something is not equal to something else, when something

71
00:05:57,260 --> 00:06:02,900
is not equal to something else, you put an exclamation mark and an equal sign like that.

72
00:06:04,390 --> 00:06:10,270
So if you want to check whether something is not equal to something else or, you know, make some sort

73
00:06:10,270 --> 00:06:17,170
of statement, it would be like, you know, for no equal to five something like that.

74
00:06:21,220 --> 00:06:27,220
So I introduced these two already, I'm going to continue on with these as well.

75
00:06:30,000 --> 00:06:37,230
But something that I'm going to do first is kind of bring back this if that we talked about in the last

76
00:06:37,230 --> 00:06:37,680
lecture.

77
00:06:37,690 --> 00:06:46,620
So this if you just saw it in a theoretical sense, but it's actually a key word inside of the C++ language,

78
00:06:48,060 --> 00:06:53,730
and it's the most basic kind of building block of conditional statements.

79
00:06:53,880 --> 00:07:05,100
So if you want to check whether something is true or false, you can use this if and what you do after

80
00:07:05,100 --> 00:07:05,490
typing.

81
00:07:05,490 --> 00:07:11,700
The word f is you put a pair of parentheses similar to like what you have here after main.

82
00:07:13,100 --> 00:07:19,190
And then inside of the parentheses, you put one of those conditional statements, so kind of like we

83
00:07:19,190 --> 00:07:20,750
had in the last lecture.

84
00:07:21,230 --> 00:07:24,800
You know, if P or Q something like that?

85
00:07:26,500 --> 00:07:32,140
So let's start off with something basic using these operators that we have right here.

86
00:07:32,920 --> 00:07:42,040
So inside of the parentheses, I'm going to say if five equals equals, we're not five.

87
00:07:42,340 --> 00:07:47,050
Yeah, I will say if I one equals equals five.

88
00:07:48,790 --> 00:07:56,800
So here's the statement I'm saying I'm putting the word if I'm putting some parentheses right here and

89
00:07:56,800 --> 00:07:59,830
inside of the parentheses, I'm taking my variable.

90
00:08:00,040 --> 00:08:09,670
I won and I am checking to see if it is equal to with this double equal sign the kind of hardcoded value

91
00:08:09,670 --> 00:08:12,130
of five, which it is right.

92
00:08:12,130 --> 00:08:17,890
I one is five because five are stored in into one right here with the assignment operator, we made

93
00:08:17,890 --> 00:08:21,160
a new variable, a new integer variable on this line right here.

94
00:08:22,950 --> 00:08:28,590
So this if statement will evaluate to true, because i1 is equal to five.

95
00:08:29,460 --> 00:08:36,150
The usefulness of it, though, is to do something when i1 is equal to five.

96
00:08:36,180 --> 00:08:44,670
So the conditional statement can be used and particularly if statement can be used to activate some

97
00:08:44,670 --> 00:08:45,780
lines of code.

98
00:08:46,380 --> 00:08:53,010
If this is true, so it's kind of like checking on something and then using the answer, whether that's

99
00:08:53,010 --> 00:08:57,750
true or false, to decide whether you want to run some of the code and the way that we run or the code

100
00:08:57,750 --> 00:09:02,550
is just kind of how we have these brackets for main.

101
00:09:02,640 --> 00:09:08,190
You notice that when the main function gets called Ember, we said the main function is called the operating

102
00:09:08,190 --> 00:09:08,610
system.

103
00:09:10,080 --> 00:09:12,990
All of the code in between these brackets.

104
00:09:12,990 --> 00:09:14,790
So you have the clothes here in the open here.

105
00:09:14,790 --> 00:09:21,690
So all in this code gets ran right when the main gets called in, kind of think of the F as running

106
00:09:21,690 --> 00:09:24,750
as well, just like main, if this is true in here.

107
00:09:25,380 --> 00:09:32,790
So if I one equals equals five, so if I want is equal to five, if that is true, then whatever is

108
00:09:32,790 --> 00:09:35,390
inside of the curly braces is going to run.

109
00:09:35,400 --> 00:09:37,800
So whatever code we put in here will run.

110
00:09:38,070 --> 00:09:40,020
Otherwise, it will not run the code.

111
00:09:40,230 --> 00:09:43,530
If this is false, it's not going to do anything in here.

112
00:09:43,530 --> 00:09:49,610
It's actually just going to continue on to whatever happens past the closed curly brace.

113
00:09:49,620 --> 00:09:54,180
So if you had more code down here, it would just jump from here.

114
00:09:54,440 --> 00:09:55,480
Oh, that's not true.

115
00:09:55,500 --> 00:09:58,860
I'm just going to continue on down to here and it would run this next line.

116
00:10:01,050 --> 00:10:07,200
So since kind of we have this pattern of just printing stuff out, let's go ahead and continue with

117
00:10:07,200 --> 00:10:07,560
that.

118
00:10:08,370 --> 00:10:19,170
So I'm going to just say, see out, I equals equals five and I put an end line there.

119
00:10:21,610 --> 00:10:27,010
And then I'm actually going to before I run this, I'm going to introduce some kind of another topic

120
00:10:27,400 --> 00:10:35,500
kind of randomly that may or may not have been introduced yet, and that is something called a comment.

121
00:10:35,620 --> 00:10:39,250
So this is just a side note kind of a thing.

122
00:10:40,840 --> 00:10:45,310
All of this right here, I would kind of want to keep it here so we can refer to it.

123
00:10:46,300 --> 00:10:52,270
Want to be able to look at all these symbols and explain them, but I don't want C++ to hit this line

124
00:10:52,270 --> 00:10:54,070
and not understand what's happening.

125
00:10:54,520 --> 00:10:56,550
I don't need C++ to run this.

126
00:10:56,560 --> 00:10:57,970
This isn't like code, right?

127
00:10:58,000 --> 00:11:05,590
This is just some sort of visual reference that we have that is being used to help us write some code

128
00:11:06,400 --> 00:11:11,710
whenever we want some sort of note or some sort of line.

129
00:11:11,920 --> 00:11:16,120
That's not runnable code, but it helps us understand our program.

130
00:11:16,810 --> 00:11:18,490
We can put something called a comment.

131
00:11:19,660 --> 00:11:25,780
And the way that you do that is just two of these slashes, you notice that this turns gray now.

132
00:11:26,790 --> 00:11:34,590
So this is totally fine, and C++ will see this, and it'll be like, OK, everything past this on this

133
00:11:34,590 --> 00:11:34,980
line.

134
00:11:34,980 --> 00:11:39,330
So all this highlighted section is not really code that I should try and compile.

135
00:11:39,960 --> 00:11:46,060
It's really just a comment that the person put in here so they can better understand the code.

136
00:11:46,080 --> 00:11:46,890
It's like a note.

137
00:11:47,990 --> 00:11:50,120
So I'm going to go ahead and leave that there.

138
00:11:50,270 --> 00:11:52,370
You can put comments wherever you want.

139
00:11:53,410 --> 00:12:00,510
Like, for example, you could say and make some integer variables.

140
00:12:01,580 --> 00:12:06,680
So that's what we're doing below this line eight, right on line nine and line 10, we're making some

141
00:12:06,680 --> 00:12:07,760
integer variables.

142
00:12:09,170 --> 00:12:16,130
Here, I could put another comment and say, make some alien rebels.

143
00:12:17,370 --> 00:12:22,470
And you'll notice that these are very important things for writing code.

144
00:12:22,890 --> 00:12:27,510
It's very good to come in your code because if someone else comes to look at your code, they might

145
00:12:27,510 --> 00:12:33,390
not understand what you're writing as far as the actual code that runs that part.

146
00:12:33,780 --> 00:12:37,440
And it's really good to make it easier for them to understand your code.

147
00:12:37,440 --> 00:12:44,250
So it's good to put comments, not everywhere, because sometimes it is obvious what a certain piece

148
00:12:44,250 --> 00:12:45,090
of code does.

149
00:12:45,420 --> 00:12:52,350
As you progress throughout learning programming, you'll notice that you'll you'll somehow be able to

150
00:12:52,350 --> 00:12:54,840
tell the right places to put comments.

151
00:12:54,840 --> 00:12:59,790
It'll just feel natural, like, Oh, this doesn't really make that much sense like this function doesn't

152
00:12:59,790 --> 00:13:00,540
make sense.

153
00:13:01,320 --> 00:13:08,070
This if statement is not so straightforward, maybe I should put a comment to say why I created it or

154
00:13:08,070 --> 00:13:09,090
what the purpose is.

155
00:13:09,090 --> 00:13:10,080
What's going on here?

156
00:13:10,080 --> 00:13:10,440
So.

157
00:13:11,850 --> 00:13:17,280
Side note here's some a way to make comments really helpful so you can go back and look at your own

158
00:13:17,280 --> 00:13:22,470
code as well, or someone else can look at your own code and understand it better.

159
00:13:23,820 --> 00:13:25,800
So with that, let's go ahead and get to it.

160
00:13:26,430 --> 00:13:28,870
I'm also going to put a return here.

161
00:13:28,890 --> 00:13:34,740
Here is the lack of it because we've kind of done it fast and it's good to put that kind of convention.

162
00:13:36,720 --> 00:13:42,030
So let's go ahead and run this, we have to find some Boolean variables, we're not really using them

163
00:13:42,030 --> 00:13:47,940
quite yet, and we've defined an integer and another integer here and we are using this.

164
00:13:49,290 --> 00:13:54,690
And I one to compare it to the value of five and try and get this to.

165
00:13:55,050 --> 00:13:58,250
So what should happen is this should print out, right?

166
00:13:58,290 --> 00:14:00,810
Because this condition in here is true.

167
00:14:01,590 --> 00:14:03,900
So let's go ahead and test it out.

168
00:14:05,640 --> 00:14:13,260
I am in just this users Dylan directory, so I'm going to need to navigate to this directory right here.

169
00:14:13,920 --> 00:14:17,460
And that's where this program will exist once I save it.

170
00:14:17,640 --> 00:14:20,340
So I'll go ahead and save, or you can just control us.

171
00:14:21,290 --> 00:14:27,860
And I'm going to use the CD command, which has changed directory and I'm going to go into first program.

172
00:14:29,000 --> 00:14:37,850
So now if I do a tour, I can bring this up and I will scroll up a bit and we have some other things

173
00:14:37,850 --> 00:14:38,630
in here, too.

174
00:14:39,380 --> 00:14:44,000
I also already have an executable in here because I've already tested this out, so I'm going to go

175
00:14:44,000 --> 00:14:45,680
ahead and remove that.

176
00:14:50,090 --> 00:14:56,190
And if I do another tour that it's not there and then, yeah, now I have this conditional slip.

177
00:14:56,960 --> 00:15:01,430
So I am in the right directory that has this file that's been saved.

178
00:15:04,160 --> 00:15:04,480
Cool.

179
00:15:05,830 --> 00:15:06,550
So.

180
00:15:07,880 --> 00:15:12,170
Let's go ahead and run this code, then we'll go ahead and compile it and then run it.

181
00:15:13,250 --> 00:15:23,090
So remember what we're going to do is a G Plus Plus and then the name of the program so conditional

182
00:15:23,090 --> 00:15:30,350
start CPP and then I'm going to do a dash because I want to name the output file and I'm just going

183
00:15:30,350 --> 00:15:33,380
to call this con e e.

184
00:15:34,100 --> 00:15:40,940
So that'll be my output executable file that we can run after we compile this press into.

185
00:15:43,290 --> 00:15:49,830
So it looks like a comp. I'm going to do there, or if you are on Lennox Al's PowerShell, you can do

186
00:15:49,830 --> 00:15:50,440
either one.

187
00:15:50,470 --> 00:15:52,050
So I'll do it last there.

188
00:15:54,410 --> 00:15:59,960
And it looks like it was successfully created the executable file.

189
00:16:01,130 --> 00:16:02,120
Go ahead and clear.

190
00:16:04,840 --> 00:16:11,080
And then now I can run that, so what I'm going to do is just to the slash, and then I would do kind

191
00:16:11,080 --> 00:16:12,210
of go easy.

192
00:16:12,970 --> 00:16:14,110
And we will run it.

193
00:16:14,260 --> 00:16:18,010
And if all is good, we should see this show up down here.

194
00:16:20,660 --> 00:16:21,050
OK.

195
00:16:21,080 --> 00:16:28,310
And we do see it show up because I one is in fact equal to five because we stored five and I won.

196
00:16:30,280 --> 00:16:35,290
All right, so let's go ahead and just change this up so we can kind of see different results.

197
00:16:35,380 --> 00:16:39,190
So if I put it to here, I two is 10, that's not equal to five, right?

198
00:16:39,880 --> 00:16:45,400
So I'm going to press up on my keyboard and go back to the compile statement here so I can just read

199
00:16:45,400 --> 00:16:46,360
compile it easily.

200
00:16:47,430 --> 00:16:52,830
Actually, I forgot to save it, so I'm going to do control SE, make sure to save it first.

201
00:16:53,970 --> 00:16:59,280
Now I will re compile it and then I can go up to run it again.

202
00:17:00,060 --> 00:17:04,360
And you notice after I run it, it just goes to another promptly and doesn't print anything out.

203
00:17:04,400 --> 00:17:07,710
That's because I too is not equal to five.

204
00:17:09,150 --> 00:17:13,060
So what what if we see if we can get this to print out again?

205
00:17:13,080 --> 00:17:21,060
I'm going to call it two, not equal to five and then let's go ahead and use this one right here.

206
00:17:21,070 --> 00:17:23,640
So this is the opposite of this.

207
00:17:24,390 --> 00:17:25,790
It is not equal.

208
00:17:25,800 --> 00:17:27,810
So when something is not able to something else.

209
00:17:27,840 --> 00:17:29,520
So let's go ahead and put this here.

210
00:17:29,550 --> 00:17:36,750
So as long as I2 is not equal to five, this will evaluate to true and then it will run this code in

211
00:17:36,750 --> 00:17:37,050
here.

212
00:17:37,380 --> 00:17:42,420
So we have an issue not equal to five in here now, and I just change this from equal, equal to not

213
00:17:42,420 --> 00:17:42,840
equal.

214
00:17:44,380 --> 00:17:52,000
So let's go ahead and save this, so control Earth, and then I'm going to recompile and then let's

215
00:17:52,000 --> 00:17:52,360
run it.

216
00:17:53,470 --> 00:17:59,950
So now we notice that it does print this out because Ita is not equal to five is a true this is a true

217
00:17:59,950 --> 00:18:00,470
statement.

218
00:18:00,490 --> 00:18:01,800
Everything that's highlighted here.

219
00:18:03,120 --> 00:18:05,490
I, too, is not equal to five, because I too is 10.

220
00:18:08,410 --> 00:18:09,970
So pretty cool.
