1
00:00:00,630 --> 00:00:02,900
Hello and welcome to this lecture.

2
00:00:02,970 --> 00:00:11,980
In this lecture I'll be explaining what conditional statements are in the Ruby programming language.

3
00:00:12,000 --> 00:00:15,660
What are conditional statements.

4
00:00:15,870 --> 00:00:26,880
Conditional state measures are basically used to perform different actions based on different conditions.

5
00:00:27,900 --> 00:00:34,770
In Ruby and most programming languages they use conditional statements.

6
00:00:34,770 --> 00:00:44,250
So when you write code you may want to perform different actions for different types of decisions.

7
00:00:44,330 --> 00:00:48,420
You do this using conditional statements.

8
00:00:48,420 --> 00:00:53,610
There are three main types of conditional statements in Ruby.

9
00:00:53,610 --> 00:00:57,420
The first is known as the if statement.

10
00:00:57,420 --> 00:01:05,950
Basically what this appears is that the piece of code inside this state may execute if the condition

11
00:01:05,950 --> 00:01:10,300
specified inside the IF statement turns out to be true.

12
00:01:10,950 --> 00:01:18,930
If the condition is false then the second type of conditional statement is executed which is the else

13
00:01:18,990 --> 00:01:19,880
statement.

14
00:01:20,160 --> 00:01:30,390
So who else will execute the code block if the condition in the block is wrong or it evaluates to be

15
00:01:31,150 --> 00:01:32,330
false.

16
00:01:32,460 --> 00:01:38,790
If it's true then there is no action for the house because the code will have executed are there is

17
00:01:38,880 --> 00:01:41,800
another conditional statement that is else.

18
00:01:41,970 --> 00:01:44,090
If so what this does.

19
00:01:44,100 --> 00:01:48,850
It basically specifies a new set of condition.

20
00:01:48,940 --> 00:01:56,850
If the condition in the first block is false so it was both fresh new condition to test the condition

21
00:01:56,910 --> 00:01:59,940
in the first block is faulkes.

22
00:01:59,940 --> 00:02:04,930
Let's quickly illustrate how this works in the first example here.

23
00:02:05,040 --> 00:02:16,950
Quite a variable x which we said is less than 17 so we think if it is less than 17 then display below

24
00:02:16,950 --> 00:02:17,670
17.

25
00:02:17,690 --> 00:02:26,850
If he is not listed in the second block of call what is it tell us if he if x is greater than 27 which

26
00:02:26,850 --> 00:02:35,200
is in new condition then display over 27 else display 17 to 20.

27
00:02:35,670 --> 00:02:43,050
So every time you write a conditional statement you must type an end so that Ruby knows you've ended

28
00:02:43,050 --> 00:02:43,950
the statement.

29
00:02:43,950 --> 00:02:48,870
Ruby is quite unique compared to more so that programming language should only curly braces and all

30
00:02:48,870 --> 00:02:56,430
that Ruby knows what to do once he gets to where each of the conditional statements are equal to what

31
00:02:56,430 --> 00:02:57,180
he has to do.

32
00:02:57,180 --> 00:03:02,610
As long as you put the end when this statement meant Ruby would do the rest.

33
00:03:02,610 --> 00:03:11,260
Another quick example is this we say we test in a quick application here to check the drinking age limit

34
00:03:11,970 --> 00:03:14,030
so we've got conditional statement.

35
00:03:14,040 --> 00:03:22,110
To do that so this is just a simple fit meant to see if this city is equal to London.

36
00:03:22,110 --> 00:03:26,020
Then set the drinking age to 18.

37
00:03:26,280 --> 00:03:31,610
Are the wise set the drinking age to 21.

38
00:03:32,580 --> 00:03:39,760
I've got interactive Ruby so I am going to illustrate how conditional stick meant work.

39
00:03:39,780 --> 00:03:46,470
I've already pre written my move so I'm just going to pace in airline at a time to save me typing.

40
00:03:46,740 --> 00:03:52,920
So first I got a variable and I've set the variable name to blue line.

41
00:03:53,130 --> 00:03:54,440
I press enter.

42
00:03:55,750 --> 00:04:01,980
So begin the conditional testing and the first is if it meant So I'm testing the condition.

43
00:04:01,990 --> 00:04:07,770
Usually when you test conditions you use in comparison operators here.

44
00:04:07,860 --> 00:04:15,760
So I'm seeing even the name that name you they mean if it is equal to blue line then I wanted to do

45
00:04:15,760 --> 00:04:23,940
whatever I specify inside this conditional state so the condition turns out to be true.

46
00:04:24,090 --> 00:04:28,210
It all executed this piece of code.

47
00:04:29,270 --> 00:04:41,350
If it is false I need to add a health condition it will execute the code I put within the health statement.

48
00:04:41,650 --> 00:04:49,410
So if the condition is wrong it will display this message on the screen.

49
00:04:49,840 --> 00:04:55,210
Nothing will happen yet because I have not ended the statement so Ruby doesn't know if I want to write

50
00:04:55,230 --> 00:04:55,810
in.

51
00:04:55,950 --> 00:04:58,080
So now I can end this statement.

52
00:04:58,120 --> 00:04:59,600
Now this statement has ended.

53
00:04:59,600 --> 00:05:04,050
If I press enter to see you are not blue line.

54
00:05:04,260 --> 00:05:12,850
What that means is that it is executing the code in the else statement because the condition in the

55
00:05:13,100 --> 00:05:16,150
statement was not true.

56
00:05:16,780 --> 00:05:21,000
All right I'm going to do another conditional this time going to include the else.

57
00:05:21,040 --> 00:05:23,740
If so and not a condition here empty.

58
00:05:23,730 --> 00:05:25,600
If the name is blueline.

59
00:05:28,040 --> 00:05:32,510
Then I want this message to be displayed.

60
00:05:32,630 --> 00:05:38,000
Blue line gives a good discount if this condition is true if it is not.

61
00:05:38,210 --> 00:05:45,490
I need to specify and else so I'm specifying an else if Okay.

62
00:05:45,500 --> 00:05:55,610
So this darton a new condition yes this testing in new condition here case so if this name if this condition

63
00:05:55,610 --> 00:06:02,690
is not met and put a new quantity on here then name me the name is sequel's to London uni then I need

64
00:06:02,690 --> 00:06:06,390
to specify the piece of code that will execute.

65
00:06:06,770 --> 00:06:15,200
So if the condition in the ELSE is true it will display come on London if it is not true.

66
00:06:15,230 --> 00:06:23,870
I need to specify and else and then specify the code that will display in the else statement.

67
00:06:24,140 --> 00:06:29,150
So the condition is not true in the Healthy of record I want to display.

68
00:06:29,150 --> 00:06:35,020
Is this inside a statement of C not London you or Kim.

69
00:06:35,030 --> 00:06:45,250
Now I mean to end the statement by typing in an end stedman's So that's it for press Enter now the conditional

70
00:06:45,260 --> 00:06:47,010
STD May will execute.

71
00:06:47,360 --> 00:06:56,030
So you can see now says blue line gives a good discount cause the condition in the if statement is true

72
00:06:56,490 --> 00:06:57,970
evaluated to true.

73
00:06:57,990 --> 00:07:01,780
So the piece of code in the else.

74
00:07:01,820 --> 00:07:08,400
If anybody else when not executed only become only the code inside here block.

75
00:07:08,540 --> 00:07:12,890
So that's basically how conditional statements work.

76
00:07:12,890 --> 00:07:15,090
Thanks for watching and buyoff for there.
