WEBVTT

00:00.420 --> 00:05.090
We saw with the IF statements you could write something like this.

00:05.100 --> 00:23.870
So let's say you and in X goes five y calls in in you had to max in zero for now say something like

00:23.930 --> 00:27.200
this if x is greater than Y

00:29.770 --> 00:36.220
then the max is X else the max is y

00:39.820 --> 00:41.830
in C out.

00:44.030 --> 00:45.800
Max is this

00:50.700 --> 00:52.140
that it's and

00:54.930 --> 01:00.720
in this set the max is 9.

01:01.320 --> 01:04.120
Well there's another way we could write this.

01:04.140 --> 01:06.760
That's a bit less code.

01:06.960 --> 01:16.830
And this is called the turn ary operator trinary means composed of three parts in it's written like

01:17.070 --> 01:21.420
this it's just that

01:28.030 --> 01:35.020
and say I'll just write the actual syntax of it.

01:35.370 --> 01:44.080
So boolean expression and then a question mark and then this is the CH

01:46.730 --> 01:48.100
expression or.

01:48.110 --> 01:56.770
Case and it's followed by a colon and then you have if all else is.

01:56.800 --> 02:00.950
So it's just like the if statement that we had before.

02:01.090 --> 02:03.350
It's just written a little bit differently.

02:03.370 --> 02:14.600
So if you wanted to make that statement again but using that Turnberry operator we could do this x greater

02:14.600 --> 02:31.230
than Y and then Max is equal to x otherwise Max equal to Y and this should be the exact same as what

02:31.230 --> 02:32.670
we had before.

02:33.180 --> 02:37.940
So see how programmers really like shortcuts.

02:37.950 --> 02:42.120
They really don't like typing a lot of characters.

02:42.120 --> 02:51.350
So we made some sort of simpler ways of creating little expressions for ourselves.

02:51.360 --> 02:55.200
So in this case this is really just the else if.

02:55.200 --> 03:05.230
Else if state so we have the condition right here and then this kind of means like Is this true.

03:05.250 --> 03:11.810
So if it is true it'll do the very first part its first expression is true expression.

03:12.000 --> 03:20.010
Otherwise basically this otherwise do the false case of a false expression.

03:20.940 --> 03:26.860
K so this is just a sort of simpler way of writing IF.

03:26.870 --> 03:27.790
ELSE.

03:27.940 --> 03:33.280
And you'll see this sometimes but I try try not to use this because it's a bit less readable.

03:34.260 --> 03:38.550
And I think if if you really like this

03:44.020 --> 03:52.240
that's a bit more understandable and readable but if you want like a very quick simple way of reading

03:53.660 --> 04:02.260
this if else control flow structure and you can write it like this too if you will.

04:02.300 --> 04:07.600
So in the next section or in the next lecture we'll do some practice problems.
