1

00:00:01,030  -->  00:00:08,500
Notice look at Donati operator if you recall we touched upon it well into using operators at the very

2

00:00:08,500  -->  00:00:11,820
beginning of the chapter so does an operator.

3

00:00:12,180  -->  00:00:17,430
But we are discussing it as part of control flow statements as it can be used as an alternative.

4

00:00:17,490  -->  00:00:21,590
If a statement we honor already seen that in certain scenarios.

5

00:00:21,670  -->  00:00:26,320
A switch statement can be used as an alternative to an IF statement.

6

00:00:26,340  -->  00:00:32,070
Similarly when it comes to Dunalley operator it can be used as an alternate to an IF statement in only

7

00:00:32,070  -->  00:00:33,100
one scenario.

8

00:00:34,660  -->  00:00:41,620
It let the operator can be used as a shorthand for if else statements that include only single statements

9

00:00:42,280  -->  00:00:50,640
that is both f block and as block cannot how more than one statement each hit is the syntax of an assignment

10

00:00:50,640  -->  00:00:55,220
statement that involves a Donati operation on the left side of the assignment.

11

00:00:55,230  -->  00:00:57,500
We have a variable on the right.

12

00:00:57,600  -->  00:01:03,720
We have an expression involuntarily operator that then any operator in good two symbols a question mark

13

00:01:03,750  -->  00:01:10,140
and a call in as I mentioned at the beginning of the chapter A eternity operator as the name suggests

14

00:01:10,240  -->  00:01:17,030
in most three options the three options are the boolean expression true expression and false expression

15

00:01:18,250  -->  00:01:22,400
if boolean expression evaluates to true then true expression is evaluated.

16

00:01:22,720  -->  00:01:29,090
Otherwise the false expression is evaluated the final expression that gets evaluated right into value

17

00:01:29,280  -->  00:01:32,780
and that value is assigned to the variable on the left side.

18

00:01:33,520  -->  00:01:38,340
Not that I that boolean expression is optional and can be used for readability.

19

00:01:40,440  -->  00:01:46,010
Unhorse are the same Donati operation can be represented using an if else statement.

20

00:01:46,110  -->  00:01:52,250
So if the boolean expression is true then the statement results equal to true expression gets executer

21

00:01:52,680  -->  00:01:56,750
otherwise the statement result equal to false expression gets executed.

22

00:01:58,140  -->  00:02:03,400
Here is a simple Donati example for computing a minimum of two numbers x and y.

23

00:02:03,960  -->  00:02:10,250
If x is less then right then the variable man gets assigned the value of X otherwise it gets this and

24

00:02:10,270  -->  00:02:17,880
the value of y so the next question is then do you study the operation in preference to an IF statement

25

00:02:17,880  -->  00:02:19,330
.

26

00:02:19,710  -->  00:02:27,420
Just like in the case of switched it meant you can use Donati if you think it improves readability.

27

00:02:27,420  -->  00:02:31,440
One example will be when we need to construct smart strings.

28

00:02:31,440  -->  00:02:37,160
For example let's say we have a program that sends out emails and the e-mail message must start with

29

00:02:37,160  -->  00:02:40,220
a customized greeting based on user's gender.

30

00:02:40,680  -->  00:02:47,520
So the gender is men then the greeting would be the text Hello followed by salutation Mr. which is then

31

00:02:47,520  -->  00:02:49,770
followed by the user's name.

32

00:02:49,770  -->  00:02:53,910
Similarly if the gender is female then the salutation has to be missed.

33

00:02:54,330  -->  00:03:00,570
So the salutation changes depending on the user's gender and for that we can make use of binary operator

34

00:03:00,660  -->  00:03:01,870
as we can see here.

35

00:03:02,800  -->  00:03:08,800
So if the metal is merely returns true then the Donati operation would read under text Mr.

36

00:03:09,220  -->  00:03:16,870
Otherwise the next Miss would be written plus operators are used to concatenate the strings the final

37

00:03:16,870  -->  00:03:19,500
string is assigned to the variable current grouping.

38

00:03:21,630  -->  00:03:25,430
Know here is the same representation using an if else statement.

39

00:03:25,780  -->  00:03:31,840
So initially the variable grading is initialized to hello and depending on the outcome of the if condition

40

00:03:32,090  -->  00:03:34,890
appropriate salutation will be appended.

41

00:03:35,020  -->  00:03:40,900
Finally name is up and that with a variable grading as you can see the Donelly version is much more

42

00:03:40,930  -->  00:03:43,560
elegant with only a single line of code.

43

00:03:45,610  -->  00:03:52,090
Similarly and they're good for using Donati is unlock statements statements print important messages

44

00:03:52,180  -->  00:03:57,640
during program exudation and they can be very useful for fixing bugs.

45

00:03:57,880  -->  00:04:02,830
Although here we are using a print aland statement in professional projects you would be using some

46

00:04:02,830  -->  00:04:08,550
kind of cataloging framework it here is an important thing to note.

47

00:04:09,050  -->  00:04:14,330
If you recall when learning about statements we mentioned about three types of statements and one of

48

00:04:14,330  -->  00:04:20,760
them was expression statements an expression statement is simply an expression appearing as a statement

49

00:04:21,600  -->  00:04:24,220
that is the expression followed by a semicolon.

50

00:04:25,220  -->  00:04:28,490
Know even a dirty operation is an expression.

51

00:04:28,550  -->  00:04:35,300
However it cannot be expressed as an expression statement that is only certain kinds of experience can

52

00:04:35,300  -->  00:04:39,310
be expressed as expression statements and not all of them.

53

00:04:39,560  -->  00:04:45,320
For example at post-road a pre-increment or a post predicament operation which is also an expression

54

00:04:45,800  -->  00:04:48,040
can be an expression statement.

55

00:04:48,050  -->  00:04:55,980
Similarly any method in Kishan can be an expression statement so basically you cannot do this and you'll

56

00:04:56,010  -->  00:04:58,300
get a compiler error if you do this.

57

00:04:58,710  -->  00:05:04,920
It needs to be part of an assignment statement or it can also be part of other kind of statements like

58

00:05:04,920  -->  00:05:08,800
metheglin location statements or even a method to that statement.

59

00:05:09,670  -->  00:05:13,930
Let's act will it be a short term goal of using it as a written statement.

60

00:05:16,230  -->  00:05:22,680
OK let's just go ahead and write a simple method call men which returns minimal off to numbers and it

61

00:05:22,680  -->  00:05:25,450
will make use of the or the operator.

62

00:05:25,600  -->  00:05:28,290
First let's define a variable called Min.

63

00:05:28,320  -->  00:05:33,900
We are in the basic democracy and it simply invokes the method meant.

64

00:05:34,210  -->  00:05:39,370
And let's just pass two parameters say nine and three.

65

00:05:39,450  -->  00:05:47,850
And let's just print this value let's call it min k now let's just go ahead and define the method also

66

00:05:47,870  -->  00:05:47,960
.

67

00:05:48,030  -->  00:06:03,460
So it's going to be a static method and men that say and X pain why so let's just define what it is

68

00:06:03,480  -->  00:06:06,780
that and it's have there been any operation

69

00:06:09,710  -->  00:06:22,450
less then by then you are done X otherwise and Y and are done it is at so let's just compile and run

70

00:06:22,450  -->  00:06:22,870
this

71

00:06:26,810  -->  00:06:28,890
as you can see to spending three.

72

00:06:28,890  -->  00:06:35,160
So we were passing nine and three and spending the the minimum value with just three.

73

00:06:35,260  -->  00:06:38,550
Now just remember that you cannot do this.

74

00:06:38,600  -->  00:06:39,840
That is eternity.

75

00:06:39,860  -->  00:06:42,830
Expression cannot be used as an expression statement.

76

00:06:43,010  -->  00:06:45,350
So let's just try to compile this.

77

00:06:45,950  -->  00:06:47,250
See it says error.

78

00:06:47,270  -->  00:06:48,480
Not a statement.

79

00:06:48,560  -->  00:06:50,180
OK so you cannot do that.

80

00:06:50,540  -->  00:06:55,310
Let's put the written statement directly because we said that it can be used as a written statement

81

00:06:55,460  -->  00:06:57,370
as part of a written statement.

82

00:06:57,890  -->  00:07:00,830
So I may just compile and run this once again.

83

00:07:03,740  -->  00:07:06,110
A search still returns three.

84

00:07:06,200  -->  00:07:07,880
So that's the only operator.

85

00:07:08,000  -->  00:07:12,600
So you can mainly use it if you think it will improve readability.

86

00:07:12,620  -->  00:07:15,570
So in that case just go ahead and use it.

87

00:07:15,590  -->  00:07:15,800
OK.

88

00:07:15,800  -->  00:07:19,480
So just go ahead and you can practice on audio operator.

89

00:07:19,520  -->  00:07:23,240
So just play around with it and that's about it.

90

00:07:23,240  -->  00:07:23,810
Thank you.

91

00:07:23,820  -->  00:07:25,020
And happy coding.
