Difference between revisions of "Ruby/C2/Logical-and-other-Operators/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 2: Line 2:
  
 
{| border=1
 
{| border=1
|| ''Time'''
+
|| '''Time'''
 
|| '''Narration'''
 
|| '''Narration'''
  
 
|-
 
|-
|  00.02
+
|  00:02
 
| Welcome to this spoken tutorial on '''Logical & Other Operators. '''
 
| Welcome to this spoken tutorial on '''Logical & Other Operators. '''
  
 
|-
 
|-
| 00.06
+
| 00:06
 
| In this tutorial we will learn  
 
| In this tutorial we will learn  
  
 
|-
 
|-
| 00.09
+
| 00:09
 
| '''Logical Operators '''
 
| '''Logical Operators '''
  
 
|-
 
|-
| 00.11
+
| 00:11
 
|'''Parallel assignment''' and  
 
|'''Parallel assignment''' and  
  
 
|-
 
|-
| 00.13
+
| 00:13
 
| '''Range Operators '''
 
| '''Range Operators '''
  
 
|-
 
|-
|  00.15
+
|  00:15
 
|Here we are using  
 
|Here we are using  
  
 
|-
 
|-
|  00.17
+
|  00:17
 
| '''Ubuntu Linux''' version 12.04  
 
| '''Ubuntu Linux''' version 12.04  
  
 
|-
 
|-
|  00.20
+
|  00:20
 
|  ''' Ruby 1.9.3  '''
 
|  ''' Ruby 1.9.3  '''
  
 
|-
 
|-
| 00.23
+
| 00:23
 
|To follow this tutorial you must know how to use ''' Terminal''' and '''Text editor''' in ''' Linux'''.  
 
|To follow this tutorial you must know how to use ''' Terminal''' and '''Text editor''' in ''' Linux'''.  
  
 
|-
 
|-
| 00.29
+
| 00:29
 
|You must also be familiar with '''irb'''  
 
|You must also be familiar with '''irb'''  
 
    
 
    
  
 
|-
 
|-
|  00.33
+
|  00:33
 
| If not, for relevant tutorials, please visit our website  
 
| If not, for relevant tutorials, please visit our website  
  
Line 53: Line 53:
  
 
|-
 
|-
| 00.38
+
| 00:38
 
|Logical Operators are also known as ''' Boolean Operators'''
 
|Logical Operators are also known as ''' Boolean Operators'''
  
 
|-
 
|-
|  00.42
+
|  00:42
 
|  because they evaluate parts of an expression  
 
|  because they evaluate parts of an expression  
  
 
|-
 
|-
| 00.45
+
| 00:45
 
|and return a ''' true''' or ''' false''' value.  
 
|and return a ''' true''' or ''' false''' value.  
  
 
|-
 
|-
| 00.48
+
| 00:48
 
|'''Logical Operators''' are,  
 
|'''Logical Operators''' are,  
  
 
|-
 
|-
| 00.51
+
| 00:51
 
| ''' double ampersand (&&)'''  that is '''(and)'''  
 
| ''' double ampersand (&&)'''  that is '''(and)'''  
  
 
|-
 
|-
| 00.54
+
| 00:54
 
| ''' double pipe '''  that is '''(or)'''  
 
| ''' double pipe '''  that is '''(or)'''  
  
 
|-
 
|-
| 00.56
+
| 00:56
 
|''' Exclamation (!)'''  that is '''(not)'''  
 
|''' Exclamation (!)'''  that is '''(not)'''  
  
 
|-
 
|-
|  01.00
+
|  01:00
 
|  '''&&(double ampersand)''' and '''and''' evaluate to '''true''' only if both the expressions are '''true.'''  
 
|  '''&&(double ampersand)''' and '''and''' evaluate to '''true''' only if both the expressions are '''true.'''  
  
 
|-
 
|-
| 01.07
+
| 01:07
 
|Second expression is evaluated only if the first is '''true. '''  
 
|Second expression is evaluated only if the first is '''true. '''  
  
 
|-
 
|-
| 01.12
+
| 01:12
 
| Difference in the two forms is, precedence
 
| Difference in the two forms is, precedence
  
 
|-
 
|-
| 01.15
+
| 01:15
 
|Symbolic '''and'''  that is'''&&(double ampersand)''' has higher precedence.  
 
|Symbolic '''and'''  that is'''&&(double ampersand)''' has higher precedence.  
  
 
|-
 
|-
| 01.20
+
| 01:20
 
|Let's us see some examples now.  
 
|Let's us see some examples now.  
  
 
|-
 
|-
| 01.22
+
| 01:22
 
|We will use '''irb''' for this.  
 
|We will use '''irb''' for this.  
  
  
 
|-
 
|-
|  01.25
+
|  01:25
 
|  Open the ''' terminal''' by pressing '''Ctrl, Alt and T''' keys simultaneously.  
 
|  Open the ''' terminal''' by pressing '''Ctrl, Alt and T''' keys simultaneously.  
  
 
|-
 
|-
|  01.31
+
|  01:31
 
|Type '''irb''' and press '''Enter''' to launch '''interactive Ruby'''
 
|Type '''irb''' and press '''Enter''' to launch '''interactive Ruby'''
  
 
|-
 
|-
|  01.36
+
|  01:36
 
| Type ''' 3 greater than 2 space double ampersand space 4 less than 5'''  
 
| Type ''' 3 greater than 2 space double ampersand space 4 less than 5'''  
  
  
 
|-
 
|-
| 01.47
+
| 01:47
 
| Press ''' Enter'''
 
| Press ''' Enter'''
  
 
|-
 
|-
|  01.49
+
|  01:49
 
| We get the output as '''true.'''
 
| We get the output as '''true.'''
  
 
|-
 
|-
| 01.53
+
| 01:53
 
|Here, '''expression1'''  that is 3>2 is '''true'''.  
 
|Here, '''expression1'''  that is 3>2 is '''true'''.  
  
 
|-
 
|-
| 01.59
+
| 01:59
 
|'''Expression 2''' that is 4<5 is also '''true.'''  
 
|'''Expression 2''' that is 4<5 is also '''true.'''  
  
 
|-
 
|-
|  02.03
+
|  02:03
 
|  Since both the expressions are '''true''', we get output as '''true.'''  
 
|  Since both the expressions are '''true''', we get output as '''true.'''  
  
  
 
|-
 
|-
| 02.08
+
| 02:08
 
|Now press '''Up Arrow''' key to get the previous command.  
 
|Now press '''Up Arrow''' key to get the previous command.  
  
 
|-
 
|-
| 02.12
+
| 02:12
 
|  And ''' replace the double ampersand''' symbol with the word ''' and.'''  
 
|  And ''' replace the double ampersand''' symbol with the word ''' and.'''  
  
 
|-
 
|-
| 02.17
+
| 02:17
 
|  Press '''Enter '''
 
|  Press '''Enter '''
  
 
|-
 
|-
|  02.19
+
|  02:19
 
|We get the same result.   
 
|We get the same result.   
  
 
|-
 
|-
|  02.22
+
|  02:22
 
| Now press up arrow key again to get the previous command.  
 
| Now press up arrow key again to get the previous command.  
  
 
|-
 
|-
|  02.27
+
|  02:27
 
| In ''' expression 1''' replace '''greater than''' sign with '''less than'''
 
| In ''' expression 1''' replace '''greater than''' sign with '''less than'''
  
  
 
|-
 
|-
| 02.32
+
| 02:32
 
|Press ''' Enter '''
 
|Press ''' Enter '''
  
 
|-
 
|-
|  02.35
+
|  02:35
 
| We get the output as '''false.'''
 
| We get the output as '''false.'''
  
 
|-
 
|-
| 02.38
+
| 02:38
 
|This is because ''' 3<2''' is '''false.'''
 
|This is because ''' 3<2''' is '''false.'''
  
 
|-
 
|-
|  02.43
+
|  02:43
 
| Since the first expression is '''false''', the second expression will not be evaluated.   
 
| Since the first expression is '''false''', the second expression will not be evaluated.   
  
 
|-
 
|-
| 02.49
+
| 02:49
 
| So, we get output as '''false.'''  
 
| So, we get output as '''false.'''  
  
 
|-
 
|-
| 02.53
+
| 02:53
 
| ''' double pipe''' and '''or''' evaluate to '''true''', if either '''expression''' is '''true.'''  
 
| ''' double pipe''' and '''or''' evaluate to '''true''', if either '''expression''' is '''true.'''  
  
 
|-
 
|-
| 02.59
+
| 02:59
 
|Second expression is evaluated only if first is '''false.'''  
 
|Second expression is evaluated only if first is '''false.'''  
  
  
 
|-
 
|-
| 03.04
+
| 03:04
 
|Difference in the two forms is '''precedence.'''  
 
|Difference in the two forms is '''precedence.'''  
  
 
|-
 
|-
| 03.07
+
| 03:07
 
|Symbolic '''or''' i.e ''' double pipe''' has higher '''precedence.'''  
 
|Symbolic '''or''' i.e ''' double pipe''' has higher '''precedence.'''  
  
 
|-
 
|-
|  03.11
+
|  03:11
 
|  Now, let's try some examples.   
 
|  Now, let's try some examples.   
  
 
|-
 
|-
| 03.15
+
| 03:15
 
|''' 10 greater than 6 space double pipe space 12 less than 7'''
 
|''' 10 greater than 6 space double pipe space 12 less than 7'''
  
 
|-
 
|-
| 03.23
+
| 03:23
 
| Press  '''Enter.'''  
 
| Press  '''Enter.'''  
  
 
|-
 
|-
| 03.26
+
| 03:26
 
|We get output as '''true.'''
 
|We get output as '''true.'''
  
 
|-
 
|-
| 03.29
+
| 03:29
 
|Here '''expression 1''' that is '''10>6''' is '''true'''.
 
|Here '''expression 1''' that is '''10>6''' is '''true'''.
  
 
|-
 
|-
| 03.35
+
| 03:35
 
| Since the first expression is '''true''' , second expression will not be evaluated.  
 
| Since the first expression is '''true''' , second expression will not be evaluated.  
  
 
|-
 
|-
| 03.40
+
| 03:40
 
|So, we get the output as '''true. '''
 
|So, we get the output as '''true. '''
  
  
 
|-
 
|-
|  03.42
+
|  03:42
 
|  Now press the '''Up Arrow''' key to get the previous command.  
 
|  Now press the '''Up Arrow''' key to get the previous command.  
  
 
|-
 
|-
|  03.46
+
|  03:46
 
|  In '''expression 1''' replace '''greater than sign''' with '''less than sign.'''
 
|  In '''expression 1''' replace '''greater than sign''' with '''less than sign.'''
  
 
|-
 
|-
|  03.52
+
|  03:52
 
|  And replace '''pipe''' symbol with the word '''or.'''  
 
|  And replace '''pipe''' symbol with the word '''or.'''  
  
 
|-
 
|-
|  03.57
+
|  03:57
 
|  Press '''Enter.'''  
 
|  Press '''Enter.'''  
  
 
|-
 
|-
| 04.00
+
| 04:00
 
|Here, '''expression1''' that is 10<6 is '''false. '''
 
|Here, '''expression1''' that is 10<6 is '''false. '''
  
 
|-
 
|-
|  04.05
+
|  04:05
 
| '''Expression 2''' that is 12<7 is also '''false. '''
 
| '''Expression 2''' that is 12<7 is also '''false. '''
  
 
|-
 
|-
|  04.10
+
|  04:10
 
|  Since both the expressions are '''false''', we get output as '''false. '''
 
|  Since both the expressions are '''false''', we get output as '''false. '''
  
 
|-
 
|-
| 04.15
+
| 04:15
 
|'''! (exclamation mark )''' and '''not''' operators return the opposite value of the expression  
 
|'''! (exclamation mark )''' and '''not''' operators return the opposite value of the expression  
  
 
|-
 
|-
|  04.20
+
|  04:20
 
|  If the '''expression''' is '''true''', '''exclamation mark'''  operator will return a '''false''' value.  
 
|  If the '''expression''' is '''true''', '''exclamation mark'''  operator will return a '''false''' value.  
  
 
|-
 
|-
| 04.27
+
| 04:27
 
|It will return '''true''' if the expression is '''false'''.  
 
|It will return '''true''' if the expression is '''false'''.  
  
 
|-
 
|-
|  04.30
+
|  04:30
 
| Difference in the two forms is '''precedence. '''
 
| Difference in the two forms is '''precedence. '''
  
 
|-
 
|-
| 04.33
+
| 04:33
 
| Symbolic '''not that is (!)'''  has higher '''precedence.'''  
 
| Symbolic '''not that is (!)'''  has higher '''precedence.'''  
  
 
|-
 
|-
|  04.37
+
|  04:37
 
|  Let's try out the '''not''' operator.  
 
|  Let's try out the '''not''' operator.  
  
 
|-
 
|-
| 04.40
+
| 04:40
 
|First type ''' 10 double equal to 10'''
 
|First type ''' 10 double equal to 10'''
  
 
|-
 
|-
|  04.45
+
|  04:45
 
|  Press '''Enter '''
 
|  Press '''Enter '''
  
 
|-
 
|-
| 04.47
+
| 04:47
 
|We get the output as '''true.'''
 
|We get the output as '''true.'''
  
 
|-
 
|-
| 04.50
+
| 04:50
 
|To invert the result of above expression,  
 
|To invert the result of above expression,  
  
 
|-
 
|-
|  04.53
+
|  04:53
 
| let's add the '''not''' operator before the expression.  
 
| let's add the '''not''' operator before the expression.  
  
  
 
|-
 
|-
| 04.57
+
| 04:57
 
|Type '''Exclamation mark within brackets 10 double equal to 10 '''
 
|Type '''Exclamation mark within brackets 10 double equal to 10 '''
  
  
 
|-
 
|-
|  05.04
+
|  05:04
 
| Press '''Enter. '''
 
| Press '''Enter. '''
  
  
 
|-
 
|-
|  05.06
+
|  05:06
 
|We get the output as '''false.'''
 
|We get the output as '''false.'''
  
 
|-
 
|-
| 05.10
+
| 05:10
 
| Press '''Ctrl+L''' simultaneously to clear the '''irb''' console.  
 
| Press '''Ctrl+L''' simultaneously to clear the '''irb''' console.  
  
 
|-
 
|-
| 05.15
+
| 05:15
 
|Next, let us learn about '''parallel assignment. '''
 
|Next, let us learn about '''parallel assignment. '''
  
 
|-
 
|-
| 05.20
+
| 05:20
 
|Multiple variables can be initialized with a single line of '''Ruby''' code, through '''parallel assignment. '''
 
|Multiple variables can be initialized with a single line of '''Ruby''' code, through '''parallel assignment. '''
  
 
|-
 
|-
| 05.26
+
| 05:26
 
| Let's switch to the '''terminal.'''
 
| Let's switch to the '''terminal.'''
  
 
|-
 
|-
| 05.29
+
| 05:29
 
|Let's declare three variables '''a, b, c''' using '''parallel assignment. '''
 
|Let's declare three variables '''a, b, c''' using '''parallel assignment. '''
  
 
|-
 
|-
| 05.36
+
| 05:36
 
| Type '''a comma b comma c equal to 10 comma 20 comma 30 '''
 
| Type '''a comma b comma c equal to 10 comma 20 comma 30 '''
  
 
|-
 
|-
| 05.45
+
| 05:45
 
| and press '''Enter. '''
 
| and press '''Enter. '''
  
 
|-
 
|-
| 05.47
+
| 05:47
 
|Here, '''10''' will be assigned to variable '''a '''
 
|Here, '''10''' will be assigned to variable '''a '''
  
 
|-
 
|-
| 05.52
+
| 05:52
 
|'''20''' will be assigned to variable '''b '''
 
|'''20''' will be assigned to variable '''b '''
  
 
|-
 
|-
| 05.54
+
| 05:54
 
|'''30''' will be assigned to variable '''c '''
 
|'''30''' will be assigned to variable '''c '''
  
  
 
|-
 
|-
| 05.56
+
| 05:56
 
|The right hand side acts as an '''array'''.  
 
|The right hand side acts as an '''array'''.  
  
 
|-
 
|-
| 06.01
+
| 06:01
 
|If we list multiple variables on the left hand side,  then the array is unpacked and assigned into the respective variables.  
 
|If we list multiple variables on the left hand side,  then the array is unpacked and assigned into the respective variables.  
  
 
|-
 
|-
| 06.10
+
| 06:10
 
|We will learn about '''arrays''' in detail in the upcoming tutorials.  
 
|We will learn about '''arrays''' in detail in the upcoming tutorials.  
  
 
|-
 
|-
| 06.14
+
| 06:14
 
| For now, let's check whether the '''assignment''' is done properly.  
 
| For now, let's check whether the '''assignment''' is done properly.  
  
 
|-
 
|-
|06.20
+
|06:20
 
| Type '''a''' and press '''Enter.'''
 
| Type '''a''' and press '''Enter.'''
  
 
|-
 
|-
| 06.23
+
| 06:23
 
|Value '''10''' stored in variable '''a''' is displayed.  
 
|Value '''10''' stored in variable '''a''' is displayed.  
  
 
|-
 
|-
| 06.28
+
| 06:28
 
|Type '''b''' and press '''Enter.'''
 
|Type '''b''' and press '''Enter.'''
  
 
|-
 
|-
| 06.31
+
| 06:31
 
|We get 20  
 
|We get 20  
  
 
|-
 
|-
|  06.33
+
|  06:33
 
| Type '''c''' and press '''Enter.'''
 
| Type '''c''' and press '''Enter.'''
  
 
|-
 
|-
| 06.37
+
| 06:37
 
|30 is displayed.  
 
|30 is displayed.  
  
  
 
|-
 
|-
|  06.40
+
|  06:40
 
|  '''Parallel assignment''' is also useful for swapping the values stored in two variables.  
 
|  '''Parallel assignment''' is also useful for swapping the values stored in two variables.  
 
|-
 
|-
| 06.45
+
| 06:45
 
|Let us swap the values of variables a and b.
 
|Let us swap the values of variables a and b.
  
 
|-
 
|-
| 06.50
+
| 06:50
 
|Type '''puts space within double quotes a equal to hash within curly brackets a comma within double quotes b equal to hash within curly brackets b'''  
 
|Type '''puts space within double quotes a equal to hash within curly brackets a comma within double quotes b equal to hash within curly brackets b'''  
  
 
|-
 
|-
| 07.11
+
| 07:11
 
| Press '''Enter. '''
 
| Press '''Enter. '''
  
 
|-
 
|-
| 07.13
+
| 07:13
 
| We get the output as '''a=10 '''
 
| We get the output as '''a=10 '''
  
 
|-
 
|-
| 07.16
+
| 07:16
 
|'''b=20 '''
 
|'''b=20 '''
  
 
|-
 
|-
| 07.20
+
| 07:20
 
|Now let's swap a and b.
 
|Now let's swap a and b.
  
 
|-
 
|-
| 07.23
+
| 07:23
 
|To do so type  
 
|To do so type  
  
 
|-
 
|-
| 07.25
+
| 07:25
 
|'''a comma b equal to b comma a '''
 
|'''a comma b equal to b comma a '''
  
 
|-
 
|-
| 07.31
+
| 07:31
 
|Press '''Enter.'''  
 
|Press '''Enter.'''  
  
 
|-
 
|-
| 07.33
+
| 07:33
 
| Press '''Up Arrow''' key twice to get the '''puts''' command and press '''Enter.'''
 
| Press '''Up Arrow''' key twice to get the '''puts''' command and press '''Enter.'''
  
 
|-
 
|-
|  07.39
+
|  07:39
 
|  We get the output as  
 
|  We get the output as  
  
 
|-
 
|-
| 07.41
+
| 07:41
 
|'''a=20 '''
 
|'''a=20 '''
  
 
|-
 
|-
| 07.44
+
| 07:44
 
| '''b=10 '''
 
| '''b=10 '''
  
  
 
|-
 
|-
| 07.47
+
| 07:47
 
| We will now learn about '''range''' in '''Ruby.'''
 
| We will now learn about '''range''' in '''Ruby.'''
  
 
|-
 
|-
| 07.50
+
| 07:50
 
|The values in a '''range''' can be numbers, characters, strings or objects.  
 
|The values in a '''range''' can be numbers, characters, strings or objects.  
  
 
|-
 
|-
| 07.58
+
| 07:58
 
|'''Ranges''' are used to express a '''sequence. '''
 
|'''Ranges''' are used to express a '''sequence. '''
  
 
|-
 
|-
| 08.02
+
| 08:02
 
|'''Sequence range''' is used to create a range of successive values.  
 
|'''Sequence range''' is used to create a range of successive values.  
  
 
|-
 
|-
| 08.06
+
| 08:06
 
|It consists of a start value, range of values and an end value.  
 
|It consists of a start value, range of values and an end value.  
  
 
|-
 
|-
| 08.13
+
| 08:13
 
|'''(..) two dot operator''' creates ''' inclusive range. '''
 
|'''(..) two dot operator''' creates ''' inclusive range. '''
  
 
|-
 
|-
| 08.16
+
| 08:16
 
|'''(...) three dot operator''' creates an '''exclusive range. '''
 
|'''(...) three dot operator''' creates an '''exclusive range. '''
  
 
|-
 
|-
| 08.20
+
| 08:20
 
|'''Ranges''' are used to identify whether a value falls within a particular range, too.  
 
|'''Ranges''' are used to identify whether a value falls within a particular range, too.  
  
 
|-
 
|-
| 08.26
+
| 08:26
 
|We do this using (===) the '''equality''' operator.   
 
|We do this using (===) the '''equality''' operator.   
  
 
|-
 
|-
| 08.30
+
| 08:30
 
|Let us try out some examples on '''ranges.'''
 
|Let us try out some examples on '''ranges.'''
  
 
|-
 
|-
| 08.33
+
| 08:33
 
|Let's switch to '''terminal. '''
 
|Let's switch to '''terminal. '''
  
 
|-
 
|-
| 08.36
+
| 08:36
 
|Type '''Within brackets 1 two dots 10 then dot to underscore a '''
 
|Type '''Within brackets 1 two dots 10 then dot to underscore a '''
  
  
 
|-
 
|-
| 08.46
+
| 08:46
 
|'''Two dot''' operator creates '''inclusive range. '''
 
|'''Two dot''' operator creates '''inclusive range. '''
  
 
|-
 
|-
| 08.50
+
| 08:50
 
|'''Inclusive operator''' includes both begin and end values in a range.  
 
|'''Inclusive operator''' includes both begin and end values in a range.  
  
 
|-
 
|-
| 08.57
+
| 08:57
 
|Here '''to_a''' method is used to convert a '''range''' to a list.  
 
|Here '''to_a''' method is used to convert a '''range''' to a list.  
  
 
|-
 
|-
| 09.03
+
| 09:03
 
|Press '''Enter. '''
 
|Press '''Enter. '''
  
 
|-
 
|-
| 09.05
+
| 09:05
 
|Here you can see the values 1 and 10 are included in the range.  
 
|Here you can see the values 1 and 10 are included in the range.  
  
 
|-
 
|-
| 09.11
+
| 09:11
 
|Now we will see an '''exclusive range''' operator.  
 
|Now we will see an '''exclusive range''' operator.  
  
 
|-
 
|-
| 09.16
+
| 09:16
 
|Type  '''Within brackets 1 three dots 10 then dot to underscore a '''
 
|Type  '''Within brackets 1 three dots 10 then dot to underscore a '''
  
 
|-
 
|-
| 09.27
+
| 09:27
 
|'''Three dot''' operator creates an '''exclusive range. '''
 
|'''Three dot''' operator creates an '''exclusive range. '''
  
 
|-
 
|-
| 09.31
+
| 09:31
 
|'''Exclusive range''' operator excludes the end value from the sequence.  
 
|'''Exclusive range''' operator excludes the end value from the sequence.  
  
 
|-
 
|-
| 09.37
+
| 09:37
 
|Press '''Enter. '''
 
|Press '''Enter. '''
  
 
|-
 
|-
| 09.39
+
| 09:39
 
|Here the end value 10 is not included in the range.  
 
|Here the end value 10 is not included in the range.  
  
  
 
|-
 
|-
| 09.45
+
| 09:45
 
|Now let's check whether 5 lies in the range of 1 to 10.  
 
|Now let's check whether 5 lies in the range of 1 to 10.  
  
 
|-
 
|-
| 09.50
+
| 09:50
 
|Type '''Within brackets 1 two dots 10 three times equal to and then 5 '''
 
|Type '''Within brackets 1 two dots 10 three times equal to and then 5 '''
  
  
 
|-
 
|-
| 10.00
+
| 10:00
 
|Press '''Enter. '''
 
|Press '''Enter. '''
  
 
|-
 
|-
| 10.02
+
| 10:02
 
|'''Equality operator''' is used to check whether a value lies in the range.  
 
|'''Equality operator''' is used to check whether a value lies in the range.  
  
 
|-
 
|-
| 10.07
+
| 10:07
 
|We get the output as '''true''' since 5 lies in the range 1 to 10.  
 
|We get the output as '''true''' since 5 lies in the range 1 to 10.  
  
 
|-
 
|-
| 10.14
+
| 10:14
 
|This brings us to the end of this Spoken Tutorial.  
 
|This brings us to the end of this Spoken Tutorial.  
  
 
|-
 
|-
| 10.17
+
| 10:17
 
|In this tutorial, we have learnt  
 
|In this tutorial, we have learnt  
  
  
 
|-
 
|-
| 10.20
+
| 10:20
 
|'''Logical operator''' i.e ''' double ampersand, double pipe and exclamation mark operators '''
 
|'''Logical operator''' i.e ''' double ampersand, double pipe and exclamation mark operators '''
  
 
|-
 
|-
| 10.27
+
| 10:27
 
|'''Parallel assignment''' Ex: a,b,c=10,20,30  
 
|'''Parallel assignment''' Ex: a,b,c=10,20,30  
  
 
|-
 
|-
| 10.34
+
| 10:34
 
|'''Range Operator  Inclusive operator '''(..) and Exclusive operator(...)'''
 
|'''Range Operator  Inclusive operator '''(..) and Exclusive operator(...)'''
  
 
|-
 
|-
| 10.39
+
| 10:39
 
|As an assignment  
 
|As an assignment  
  
 
|-
 
|-
| 10.41
+
| 10:41
 
|Declare two variables using '''parallel assignment''' and  
 
|Declare two variables using '''parallel assignment''' and  
  
 
|-
 
|-
| 10.45
+
| 10:45
 
|Check whether their sum lies between 20 and 50  
 
|Check whether their sum lies between 20 and 50  
  
  
 
|-
 
|-
|  10.49
+
|  10:49
 
|  Watch the video available at the following link.
 
|  Watch the video available at the following link.
  
 
|-
 
|-
| 10.52
+
| 10:52
 
|It summarises the Spoken Tutorial project.
 
|It summarises the Spoken Tutorial project.
  
 
|-
 
|-
| 10.56
+
| 10:56
 
|If you do not have good bandwidth, you can download and  watch it.  
 
|If you do not have good bandwidth, you can download and  watch it.  
  
 
|-
 
|-
|  11.00
+
|  11:00
 
|  The Spoken Tutorial Project Team :
 
|  The Spoken Tutorial Project Team :
  
 
|-   
 
|-   
| 11.03
+
| 11:03
 
|Conducts workshops using spoken tutorials  
 
|Conducts workshops using spoken tutorials  
  
 
|-
 
|-
|11.05
+
|11:05
 
|Gives certificates to those who pass an online test  
 
|Gives certificates to those who pass an online test  
  
 
|-
 
|-
| 11.09
+
| 11:09
 
|For more details, please write to contact@spoken-tutorial.org
 
|For more details, please write to contact@spoken-tutorial.org
  
 
|-
 
|-
|  11.15
+
|  11:15
 
|  Spoken Tutorial Project is a part of the Talk to a Teacher project.
 
|  Spoken Tutorial Project is a part of the Talk to a Teacher project.
  
 
|-
 
|-
| 11.19
+
| 11:19
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
  
 
|-
 
|-
| 11.25
+
| 11:25
 
|More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
 
|More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
  
 
|-
 
|-
| 11.34
+
| 11:34
 
|This script has been contributed by the spoken tutorial team IIT Bombay  
 
|This script has been contributed by the spoken tutorial team IIT Bombay  
  
 
|-
 
|-
| 11.38
+
| 11:38
 
|And this is Shalini Nair signing off  Thank you  
 
|And this is Shalini Nair signing off  Thank you  
  
  
 
|}
 
|}

Revision as of 15:32, 10 July 2014


Time Narration
00:02 Welcome to this spoken tutorial on Logical & Other Operators.
00:06 In this tutorial we will learn
00:09 Logical Operators
00:11 Parallel assignment and
00:13 Range Operators
00:15 Here we are using
00:17 Ubuntu Linux version 12.04
00:20 Ruby 1.9.3
00:23 To follow this tutorial you must know how to use Terminal and Text editor in Linux.
00:29 You must also be familiar with irb


00:33 If not, for relevant tutorials, please visit our website


00:38 Logical Operators are also known as Boolean Operators
00:42 because they evaluate parts of an expression
00:45 and return a true or false value.
00:48 Logical Operators are,
00:51 double ampersand (&&) that is (and)
00:54 double pipe that is (or)
00:56 Exclamation (!) that is (not)
01:00 &&(double ampersand) and and evaluate to true only if both the expressions are true.
01:07 Second expression is evaluated only if the first is true.
01:12 Difference in the two forms is, precedence
01:15 Symbolic and that is&&(double ampersand) has higher precedence.
01:20 Let's us see some examples now.
01:22 We will use irb for this.


01:25 Open the terminal by pressing Ctrl, Alt and T keys simultaneously.
01:31 Type irb and press Enter to launch interactive Ruby
01:36 Type 3 greater than 2 space double ampersand space 4 less than 5


01:47 Press Enter
01:49 We get the output as true.
01:53 Here, expression1 that is 3>2 is true.
01:59 Expression 2 that is 4<5 is also true.
02:03 Since both the expressions are true, we get output as true.


02:08 Now press Up Arrow key to get the previous command.
02:12 And replace the double ampersand symbol with the word and.
02:17 Press Enter
02:19 We get the same result.
02:22 Now press up arrow key again to get the previous command.
02:27 In expression 1 replace greater than sign with less than


02:32 Press Enter
02:35 We get the output as false.
02:38 This is because 3<2 is false.
02:43 Since the first expression is false, the second expression will not be evaluated.
02:49 So, we get output as false.
02:53 double pipe and or evaluate to true, if either expression is true.
02:59 Second expression is evaluated only if first is false.


03:04 Difference in the two forms is precedence.
03:07 Symbolic or i.e double pipe has higher precedence.
03:11 Now, let's try some examples.
03:15 10 greater than 6 space double pipe space 12 less than 7
03:23 Press Enter.
03:26 We get output as true.
03:29 Here expression 1 that is 10>6 is true.
03:35 Since the first expression is true , second expression will not be evaluated.
03:40 So, we get the output as true.


03:42 Now press the Up Arrow key to get the previous command.
03:46 In expression 1 replace greater than sign with less than sign.
03:52 And replace pipe symbol with the word or.
03:57 Press Enter.
04:00 Here, expression1 that is 10<6 is false.
04:05 Expression 2 that is 12<7 is also false.
04:10 Since both the expressions are false, we get output as false.
04:15 ! (exclamation mark ) and not operators return the opposite value of the expression
04:20 If the expression is true, exclamation mark operator will return a false value.
04:27 It will return true if the expression is false.
04:30 Difference in the two forms is precedence.
04:33 Symbolic not that is (!) has higher precedence.
04:37 Let's try out the not operator.
04:40 First type 10 double equal to 10
04:45 Press Enter
04:47 We get the output as true.
04:50 To invert the result of above expression,
04:53 let's add the not operator before the expression.


04:57 Type Exclamation mark within brackets 10 double equal to 10


05:04 Press Enter.


05:06 We get the output as false.
05:10 Press Ctrl+L simultaneously to clear the irb console.
05:15 Next, let us learn about parallel assignment.
05:20 Multiple variables can be initialized with a single line of Ruby code, through parallel assignment.
05:26 Let's switch to the terminal.
05:29 Let's declare three variables a, b, c using parallel assignment.
05:36 Type a comma b comma c equal to 10 comma 20 comma 30
05:45 and press Enter.
05:47 Here, 10 will be assigned to variable a
05:52 20 will be assigned to variable b
05:54 30 will be assigned to variable c


05:56 The right hand side acts as an array.
06:01 If we list multiple variables on the left hand side, then the array is unpacked and assigned into the respective variables.
06:10 We will learn about arrays in detail in the upcoming tutorials.
06:14 For now, let's check whether the assignment is done properly.
06:20 Type a and press Enter.
06:23 Value 10 stored in variable a is displayed.
06:28 Type b and press Enter.
06:31 We get 20
06:33 Type c and press Enter.
06:37 30 is displayed.


06:40 Parallel assignment is also useful for swapping the values stored in two variables.
06:45 Let us swap the values of variables a and b.
06:50 Type puts space within double quotes a equal to hash within curly brackets a comma within double quotes b equal to hash within curly brackets b
07:11 Press Enter.
07:13 We get the output as a=10
07:16 b=20
07:20 Now let's swap a and b.
07:23 To do so type
07:25 a comma b equal to b comma a
07:31 Press Enter.
07:33 Press Up Arrow key twice to get the puts command and press Enter.
07:39 We get the output as
07:41 a=20
07:44 b=10


07:47 We will now learn about range in Ruby.
07:50 The values in a range can be numbers, characters, strings or objects.
07:58 Ranges are used to express a sequence.
08:02 Sequence range is used to create a range of successive values.
08:06 It consists of a start value, range of values and an end value.
08:13 (..) two dot operator creates inclusive range.
08:16 (...) three dot operator creates an exclusive range.
08:20 Ranges are used to identify whether a value falls within a particular range, too.
08:26 We do this using (===) the equality operator.
08:30 Let us try out some examples on ranges.
08:33 Let's switch to terminal.
08:36 Type Within brackets 1 two dots 10 then dot to underscore a


08:46 Two dot operator creates inclusive range.
08:50 Inclusive operator includes both begin and end values in a range.
08:57 Here to_a method is used to convert a range to a list.
09:03 Press Enter.
09:05 Here you can see the values 1 and 10 are included in the range.
09:11 Now we will see an exclusive range operator.
09:16 Type Within brackets 1 three dots 10 then dot to underscore a
09:27 Three dot operator creates an exclusive range.
09:31 Exclusive range operator excludes the end value from the sequence.
09:37 Press Enter.
09:39 Here the end value 10 is not included in the range.


09:45 Now let's check whether 5 lies in the range of 1 to 10.
09:50 Type Within brackets 1 two dots 10 three times equal to and then 5


10:00 Press Enter.
10:02 Equality operator is used to check whether a value lies in the range.
10:07 We get the output as true since 5 lies in the range 1 to 10.
10:14 This brings us to the end of this Spoken Tutorial.
10:17 In this tutorial, we have learnt


10:20 Logical operator i.e double ampersand, double pipe and exclamation mark operators
10:27 Parallel assignment Ex: a,b,c=10,20,30
10:34 Range Operator Inclusive operator (..) and Exclusive operator(...)
10:39 As an assignment
10:41 Declare two variables using parallel assignment and
10:45 Check whether their sum lies between 20 and 50


10:49 Watch the video available at the following link.
10:52 It summarises the Spoken Tutorial project.
10:56 If you do not have good bandwidth, you can download and watch it.
11:00 The Spoken Tutorial Project Team :
11:03 Conducts workshops using spoken tutorials
11:05 Gives certificates to those who pass an online test
11:09 For more details, please write to contact@spoken-tutorial.org
11:15 Spoken Tutorial Project is a part of the Talk to a Teacher project.
11:19 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
11:25 More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
11:34 This script has been contributed by the spoken tutorial team IIT Bombay
11:38 And this is Shalini Nair signing off Thank you


Contributors and Content Editors

PoojaMoolya, Pratik kamble, Ranjana, Sandhya.np14