Difference between revisions of "PERL/C2/Conditional-statements/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!  <center>'''Visual Cue'''</center>
+
| '''Time'''
!  <center>'''Narration'''</center>
+
| '''Narration'''
 
   
 
   
 
|-
 
|-
| 00.01
+
| 00:01
|Welcome to the spoken tutorial on if and if-else conditional statements in Perl.
+
|Welcome to the spoken tutorial on '''if and if-else conditional statements''' in '''PERL'''.
 
   
 
   
 
|-
 
|-
| 00.07
+
| 00:07
| In this tutorial, we will learn about;
+
| In this tutorial, we will learn about:
  
 
|-
 
|-
|00.09
+
|00:09
|'''if ''' statement and  
+
|'''if ''' statement and  
  
 
|-
 
|-
|00.11
+
|00:11
|''' if-else''' statement in Perl  
+
|''' if-else''' statement in Perl.  I am using '''Ubuntu Linux 12.04''' operating system and '''Perl 5.14.2'''.
 
   
 
   
 
|-
 
|-
|00.12
+
|00:20
| I am using '''Ubuntu Linux12.04''' operating system and '''Perl 5.14.2'''
+
+
+
|-
+
|00.20
+
 
|I will also be using the '''gedit Text Editor'''.
 
|I will also be using the '''gedit Text Editor'''.
+
 
+
 
|-
 
|-
|00.24
+
|00:24
 
|You can use any text editor of your choice.
 
|You can use any text editor of your choice.
 
   
 
   
 
|-
 
|-
| 00.28
+
| 00:28
| You should have basic knowledge of '''Variables '''and''' Comments '''in''' Perl.'''
+
| You should have basic knowledge of variables and '''comments''' in''' Perl.'''
+
 
   
 
   
 
|-
 
|-
|00.33
+
|00:33
|Knowledge of '''for''', '''foreach''' , '''while and  do-while '''loops in '''Perl''' will be an added advantage.
+
|Knowledge of '''for''', '''foreach''' , '''while''' and  '''do-while '''loops in '''Perl''' will be an added advantage.
  
 
|-
 
|-
|00.40
+
|00:40
|Please go through the relevant spoken tutorials on the spoken tutorial website.  
+
|Please go through the relevant spoken tutorials on the '''Spoken Tutorial''' website.  
 
   
 
   
 
|-
 
|-
| 00.45
+
| 00:45
| Perl provides the following conditional statements -
+
| Perl provides the following conditional statements:
 
   
 
   
 
|-
 
|-
|00.49
+
|00:49
|'''if'''
+
| '''if''',  '''if-else '''
 
   
 
   
 
|-
 
|-
|00.50
+
|00:51
|'''if-else '''
+
| '''if-elsif-else''' and  
+
|-
+
|00.51
+
|'''if-elsif-else''' and  
+
+
|-
+
|00.53
+
|'''switch '''
+
+
 
   
 
   
 
|-
 
|-
|00.54
+
|00:53
|In this tutorial, we'll cover '''if '''and '''If-else''' statements  
+
|'''switch '''.In this tutorial, we will cover '''if '''and '''if-else''' statements.
 
   
 
   
 
|-
 
|-
|00.59
+
|00:59
 
|'''if'''  statement in '''Perl''' can be used  
 
|'''if'''  statement in '''Perl''' can be used  
 
   
 
   
 
|-
 
|-
| 01.01
+
| 01:01
 
| to execute a piece of code only when a specified condition is satisfied.  
 
| to execute a piece of code only when a specified condition is satisfied.  
  
 
|-
 
|-
|01.07
+
|01:07
|The syntax of '''if''' conditional statement is as follows  
+
|The syntax of '''if''' conditional statement is as follows:
+
 
   
 
   
 
|-
 
|-
|01.11
+
|01:11
|'''if '''space open bracket '''condition''' close bracket space Open curly bracket  
+
|'''if''' space open bracket '''condition''' close bracket space open curly bracket  
+
 
   
 
   
 
|-
 
|-
|01.19
+
|01:19
|'''Enter'''
+
|'''Enter'''.Piece of code semicolon to be executed when the condition is true 
 
   
 
   
 
|-
 
|-
|01.20
+
|01:25
|Piece of code semicolon,  to be executed when the condition is true 
+
| '''Enter''' close curly bracket.
 
+
 
   
 
   
 
|-
 
|-
|01.25
+
|01:29
| '''Enter''', Close curly bracket
+
|The code inside the '''if''' statement will be executed only when the '''condition''' is true.
+
 
   
 
   
 
|-
 
|-
|01.29
+
|01:36
|The code inside the '''if''' statement will be executed only when the condition is true.  
+
| Now, let us look at an example of '''if ''' statement.  
 
   
 
   
 
|-
 
|-
|01.36
+
| 01:40
| Now let us look at an example of '''if ''' statement.
+
|Open the Terminal and type:
 
   
 
   
 
|-
 
|-
| 01.40
+
|01:43
|Open the Terminal and type
+
|'''gedit conditionalBlocks dot pl''' space '''&'''(ampersand )
 
   
 
   
 
|-
 
|-
|01.43
+
|01:49
|'''gedit conditionalBlocks dot pl ''' space '''&'''(ampersand )
+
|and press '''Enter'''.
 
   
 
   
 
|-
 
|-
|01.49
+
|01:52
|and press '''Enter'''
+
|This will open the '''conditionalBlocks.pl''' file in '''gedit'''.
 
   
 
   
 
|-
 
|-
|01.52
+
|01:57
|This will open the '''conditionalBlocks.pl''' file in gedit.
+
+
|-
+
|01.57
+
 
|Type the following piece of code as displayed on the screen.  
 
|Type the following piece of code as displayed on the screen.  
 
   
 
   
 
|-
 
|-
|02.02
+
|02:02
|Here we have specified a condition for '''if''' which checks the value of variable count.  
+
|Here we have specified a condition for '''if''' which checks the value of variable '''count'''.  
+
 
   
 
   
 
|-
 
|-
|02.09
+
|02:09
| Note the equal to equal to sign here. This is the '''comparison''' operator.  
+
| Note the '''equal to equal to''' sign here. This is the comparison operator.  
  
 
|-
 
|-
|02.15
+
|02:15
|The condition '''$count equal to equal to 5 ''' is checked against the value of variable count.  
+
|The condition '''$count equal to equal to 5 ''' is checked against the value of variable '''count'''.  
  
 
 
|-
 
|-
|02.23
+
|02:23
|When it is equal to 5, the code within the if block will get executed.  
+
|When it is equal to 5, the code within the '''if''' block will get executed.  
 
   
 
   
 
|-
 
|-
| 02.28
+
| 02:28
 
|Now, press '''ctrl+s''' to '''save''' the file.  
 
|Now, press '''ctrl+s''' to '''save''' the file.  
  
 
|-
 
|-
|02.32
+
|02:32
 
|Then switch to the terminal.  
 
|Then switch to the terminal.  
  
 
|-
 
|-
|02.36
+
|02:36
 
| Make sure that you are in the directory in which you have saved your file.  
 
| Make sure that you are in the directory in which you have saved your file.  
 
   
 
   
 
|-
 
|-
|02.41
+
|02:41
|Type the following to check for any compilation or syntax error -
+
|Type the following to check for any compilation or syntax error
 
   
 
   
 
|-
 
|-
|02.46
+
|02:46
 
|'''perl hyphen c conditionalBlocks dot pl'''
 
|'''perl hyphen c conditionalBlocks dot pl'''
  
 
|-
 
|-
| 02.53
+
| 02:53
| and press '''Enter. '''
+
|and press '''Enter. '''
 
   
 
   
 
|-
 
|-
|02.55
+
|02:55
|The following line will be displayed on the terminal window   
+
|The following line will be displayed on the terminal window:  
 
   
 
   
 
|-
 
|-
|  02.59
+
|  02:59
| '''conditionalBlocks.pl syntax OK '''
+
| "conditionalBlocks.pl syntax OK".
  
 
 
|-
 
|-
|   03.04
+
|03:04
| As there is no compilation or syntax error, we will execute the Perl script by typing -
+
| As there is no compilation or syntax error, we will execute the Perl script by typing:
+
 
   
 
   
 
|-
 
|-
|03.10
+
|03:10
 
|'''perl conditionalBlocks dot pl '''
 
|'''perl conditionalBlocks dot pl '''
 
   
 
   
 
|-
 
|-
| 03.14
+
| 03:14
| and press '''Enter'''
+
| and press '''Enter'''.
+
 
   
 
   
 
|-
 
|-
|03.16
+
|03:16
 
|The following output will be shown on terminal.  
 
|The following output will be shown on terminal.  
 
   
 
   
 
|-
 
|-
| 03.19
+
| 03:19
| ''' I am inside if statement'''
+
| "I am inside if statement".
 
   
 
   
 
|-
 
|-
| 03.23
+
| 03:23
|Switch back to gedit
+
|Switch back to '''gedit'''.
 
   
 
   
 
|-
 
|-
|03.26
+
|03:26
|Alternately, we can write the above ''' if''' statement as-
+
|Alternately, we can write the above ''' if''' statement as:
 
   
 
   
 
|-
 
|-
|03.31
+
|03:31
|'''print ''' space double quote '''I am inside if statement''' slash '''n''' double quote complete space '''if''' open bracket '''dollar count equal to equal to 5''' close bracket semicolon.
+
|'''print''' space double quotes '''I am inside if statement''' backslash '''n''' close double quotes space '''if''' space open bracket '''dollar count space equal to equal to space 5''' close bracket semicolon.
  
 
|-
 
|-
| 03.57
+
| 03:57
 
|Now, let us look at '''if-else''' statement.  
 
|Now, let us look at '''if-else''' statement.  
 
   
 
   
 
|-
 
|-
|04.01
+
|04:01
|This statement is used when user wants to execute  
+
|This statement is used when user wants to execute-
+
 
   
 
   
 
|-
 
|-
|04.06
+
|04:06
|one piece of code when the condition is true and  
+
|one piece of code when the condition is '''True''' and  
 
   
 
   
 
|-
 
|-
| 04.09
+
|04:09
| another piece of code when the condition is false
+
| another piece of code when the condition is '''False'''.
  
 
|-
 
|-
|   04.13
+
|04:13
| The syntax for '''if-else''' condition is as follows -
+
| The syntax for '''if-else''' condition is as follows:
  
 
|-
 
|-
| 04.17
+
|04:17
| '''if ''' space open bracket '''condition''' close bracket space open curly bracket Press Enter.  
+
| '''if ''' space open bracket '''condition''' close bracket space open curly bracket Press '''Enter'''.  
 
   
 
   
 
|-
 
|-
| 04.27
+
|04:27
 
|piece of code semicolon  
 
|piece of code semicolon  
  
 
|-
 
|-
| 04.29
+
|04:29
| to be executed when if condition is true,  
+
| to be executed when '''if''' condition is '''true''',  
+
 
   
 
   
 
|-
 
|-
|04.32
+
|04:32
|Press '''Enter '''
+
|press '''Enter '''
  
 
|-
 
|-
|04.34
+
|04:34
 
|close curly bracket space '''else''' space open curly bracket '''Enter'''
 
|close curly bracket space '''else''' space open curly bracket '''Enter'''
 
   
 
   
 
|-
 
|-
|04.41
+
|04:41
| another piece of code semicolon  
+
| another piece of code semicolon  
 
+
 
   
 
   
 
|-
 
|-
|04.43
+
|04:43
|to be executed when if condition is false  
+
|to be executed when '''if''' condition is '''false'''
  
 
|-
 
|-
|04.47
+
|04:47
|Press '''Enter''' close curly bracket  
+
|press '''Enter''' close curly bracket.
  
 
|-
 
|-
|04.51
+
|04:51
| Now again, go to the '''conditionalBlocks.pl''' file which we have already created in gedit.  
+
| Now, again go to the '''conditionalBlocks.pl''' file which we have already created in '''gedit'''.  
 
   
 
   
 
|-
 
|-
| 04.58
+
| 04:58
| Assign 4 to count variable then at the end of the if block type space  
+
| Assign 4 to '''count''' variable. Then at the end of the '''if''' block, type: space  
  
 
|-
 
|-
| 05.07
+
| 05:07
| ''' else '''
+
|''' else '''
 
   
 
   
 
|-
 
|-
|05.09
+
|05:09
 
| space open curly bracket press '''Enter '''
 
| space open curly bracket press '''Enter '''
  
 
|-
 
|-
|05.14
+
|05:14
|'''print''' space double quote '''I am inside else statement slash n'''  double quotes complete semicolon  
+
|'''print''' space double quotes '''I am inside else statement backslash n'''  double quotes complete semicolon.
 
   
 
   
 
|-
 
|-
|05.30
+
|05:30
|Press '''Enter''' and close the '''curly bracket.'''
+
|Press '''Enter''' and close curly bracket.  
  
 
|-
 
|-
|05.34
+
|05:34
|Here, '''4''' is assigned to variable $count.
+
|Here, 4 is assigned to variable '''$count.'''
 
   
 
   
 
|-
 
|-
|05.38
+
|05:38
|As the value of count variable does not match 5,   
+
|As the value of '''count''' variable does not match 5,   
  
 
|-
 
|-
|05.43
+
|05:43
|the code within the '''if''' block will not get execute
+
|the code within the '''if''' block will not get executed.
 
   
 
   
 
|-
 
|-
|05.47
+
|05:47
|instead the code within the else block will get execute.
+
|Instead, the code within the '''else''' block will get executed.
 
   
 
   
 
|-
 
|-
|05.52
+
|05:52
|Now press Ctrl+S to save the file.  
+
|Now press ''' Ctrl+S''' to '''save''' the file.  
 
   
 
   
 
|-
 
|-
| 05.56
+
|05:56
| Now switch to terminal.
+
| Now switch to terminal
 
   
 
   
 
|-
 
|-
|05.59
+
|05:59
|and type '''perl hyphen c conditionalBlocks dot pl''' to check for any compilation or syntax error
+
|and type: '''perl hyphen c conditionalBlocks dot pl''' to check for any compilation or syntax error.
 
+
 
   
 
   
 
|-
 
|-
| 06.11
+
|06:11
| and press '''Enter'''
+
|Now, press '''Enter'''.
  
 
|-
 
|-
| 06.13
+
|06:13
| The following line will be displayed on the terminal  
+
|The following line will be displayed on the terminal:
 
   
 
   
 
|-
 
|-
| 06.17
+
|06:17
| '''conditionalBlocks.pl''' syntax OK  
+
|"conditionalBlocks.pl syntax OK"
  
 
|-
 
|-
| 06.20
+
|06:20
|As there is no compilation or syntax error, we will now execute the Perl script.  
+
|As there is no compilation or syntax error, we will now execute the '''Perl script'''.  
 
   
 
   
 
|-
 
|-
|06.27
+
|06:27
|Type '''perl conditionalBlocks dot pl '''
+
|Type: '''perl conditionalBlocks dot pl '''
 
+
  
 
|-
 
|-
| 06.33
+
|06:33
| and press '''Enter'''
+
|and press '''Enter'''.
  
 
|-
 
|-
| 06.35
+
|06:35
 
| The following output will be shown on terminal.   
 
| The following output will be shown on terminal.   
  
 
|-
 
|-
|06.39
+
|06:39
|'''I am inside else statement'''
+
|"I am inside else statement".
 
   
 
   
 
|-
 
|-
| 06.44
+
| 06:44
 
|Let us summarize.   
 
|Let us summarize.   
 
   
 
   
 
|-
 
|-
| 06.46
+
| 06:46
| In this tutorial, we have learnt -
+
| In this tutorial, we have learnt:
+
|-
+
|06.49
+
|'''if''' and
+
 
   
 
   
 
|-
 
|-
|06.50
+
|06:49
|'''if-else''' conditional statements in Perl  
+
|'''if''' and '''if-else''' conditional statements in Perl  
 
   
 
   
 
|-
 
|-
| 06.53
+
| 06:53
|   using sample programs.  
+
| using sample programs.  
  
 
|-
 
|-
|  06.55
+
|  06:55
| Here is assignment for you -  
+
| Here is an assignment for you:  
 
   
 
   
 
|-
 
|-
|  06.57
+
|  06:57
| Print ''' “It is an open source language” '''
+
| Print “It is an open source language”
  
 
|-
 
|-
|07.01
+
|07:01
| when the variable declared has value ''' 'Perl' '''
+
| when the variable declared has value 'Perl'  
  
 
|-
 
|-
|07.04
+
|07:04
|otherwise print ''' “It's a proprietary language” '''
+
|otherwise, print “It's a proprietary language”.
 
   
 
   
 
|-
 
|-
|07.08
+
|07:08
|Watch the video available at the following link  
+
|Watch the video available at the following link.
  
 
|-
 
|-
|07.11
+
|07:11
|It summaries the Spoken Tutorial project
+
|It summarizes the Spoken Tutorial project.
+
 
   
 
   
 
|-
 
|-
|07.15
+
|07:15
|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.
 
   
 
   
 
|-
 
|-
| 07.20
+
| 07:20
| The Spoken Tutorial Project Team
+
| The Spoken Tutorial project team:
  
 
|-
 
|-
| 07.22
+
| 07:22
| Conducts workshops using spoken tutorials
+
|Conducts workshops using spoken tutorials.
 
   
 
   
 
 
|-
 
|-
|07.26
+
|07:26
|Gives certificates to those who pass an online test
+
| Gives certificates to those who pass an online test.
+
 
   
 
   
 
|-
 
|-
|07.31
+
|07:31
|For more details, please write to contact at spoken hyphen tutorial dot org
+
|For more details, please write to contact at spoken hyphen tutorial dot org.
 
   
 
   
 
|-
 
|-
| 07.37
+
| 07:37
|  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.
+
 
   
 
   
 
|-
 
|-
|07.42
+
|07:42
 
|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.
+
 
+
 
|-
 
|-
|07.50
+
|07:50
|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.
 
   
 
   
 
|-
 
|-
| 08.00
+
| 08:00
| Hope you enjoyed this Perl tutorial.  
+
| Hope you enjoyed this '''Perl''' tutorial.  
 
   
 
   
 
|-
 
|-
|08.04
+
|08:04
|This is Amol Brahmankar signing off.
+
|This is Amol Brahmankar, signing off.
+
 
+
 
|-
 
|-
|08.06
+
|08:06
 
|Thanks for joining.
 
|Thanks for joining.
 
   
 
   
 
|}
 
|}

Latest revision as of 15:24, 10 March 2017

Time Narration
00:01 Welcome to the spoken tutorial on if and if-else conditional statements in PERL.
00:07 In this tutorial, we will learn about:
00:09 if statement and
00:11 if-else statement in Perl. I am using Ubuntu Linux 12.04 operating system and Perl 5.14.2.
00:20 I will also be using the gedit Text Editor.
00:24 You can use any text editor of your choice.
00:28 You should have basic knowledge of variables and comments in Perl.
00:33 Knowledge of for, foreach , while and do-while loops in Perl will be an added advantage.
00:40 Please go through the relevant spoken tutorials on the Spoken Tutorial website.
00:45 Perl provides the following conditional statements:
00:49 if, if-else
00:51 if-elsif-else and
00:53 switch .In this tutorial, we will cover if and if-else statements.
00:59 if statement in Perl can be used
01:01 to execute a piece of code only when a specified condition is satisfied.
01:07 The syntax of if conditional statement is as follows:
01:11 if space open bracket condition close bracket space open curly bracket
01:19 Enter.Piece of code semicolon to be executed when the condition is true
01:25 Enter close curly bracket.
01:29 The code inside the if statement will be executed only when the condition is true.
01:36 Now, let us look at an example of if statement.
01:40 Open the Terminal and type:
01:43 gedit conditionalBlocks dot pl space &(ampersand )
01:49 and press Enter.
01:52 This will open the conditionalBlocks.pl file in gedit.
01:57 Type the following piece of code as displayed on the screen.
02:02 Here we have specified a condition for if which checks the value of variable count.
02:09 Note the equal to equal to sign here. This is the comparison operator.
02:15 The condition $count equal to equal to 5 is checked against the value of variable count.
02:23 When it is equal to 5, the code within the if block will get executed.
02:28 Now, press ctrl+s to save the file.
02:32 Then switch to the terminal.
02:36 Make sure that you are in the directory in which you have saved your file.
02:41 Type the following to check for any compilation or syntax error:
02:46 perl hyphen c conditionalBlocks dot pl
02:53 and press Enter.
02:55 The following line will be displayed on the terminal window:
02:59 "conditionalBlocks.pl syntax OK".
03:04 As there is no compilation or syntax error, we will execute the Perl script by typing:
03:10 perl conditionalBlocks dot pl
03:14 and press Enter.
03:16 The following output will be shown on terminal.
03:19 "I am inside if statement".
03:23 Switch back to gedit.
03:26 Alternately, we can write the above if statement as:
03:31 print space double quotes I am inside if statement backslash n close double quotes space if space open bracket dollar count space equal to equal to space 5 close bracket semicolon.
03:57 Now, let us look at if-else statement.
04:01 This statement is used when user wants to execute-
04:06 one piece of code when the condition is True and
04:09 another piece of code when the condition is False.
04:13 The syntax for if-else condition is as follows:
04:17 if space open bracket condition close bracket space open curly bracket Press Enter.
04:27 piece of code semicolon
04:29 to be executed when if condition is true,
04:32 press Enter
04:34 close curly bracket space else space open curly bracket Enter
04:41 another piece of code semicolon
04:43 to be executed when if condition is false
04:47 press Enter close curly bracket.
04:51 Now, again go to the conditionalBlocks.pl file which we have already created in gedit.
04:58 Assign 4 to count variable. Then at the end of the if block, type: space
05:07 else
05:09 space open curly bracket press Enter
05:14 print space double quotes I am inside else statement backslash n double quotes complete semicolon.
05:30 Press Enter and close curly bracket.
05:34 Here, 4 is assigned to variable $count.
05:38 As the value of count variable does not match 5,
05:43 the code within the if block will not get executed.
05:47 Instead, the code within the else block will get executed.
05:52 Now press Ctrl+S to save the file.
05:56 Now switch to terminal
05:59 and type: perl hyphen c conditionalBlocks dot pl to check for any compilation or syntax error.
06:11 Now, press Enter.
06:13 The following line will be displayed on the terminal:
06:17 "conditionalBlocks.pl syntax OK"
06:20 As there is no compilation or syntax error, we will now execute the Perl script.
06:27 Type: perl conditionalBlocks dot pl
06:33 and press Enter.
06:35 The following output will be shown on terminal.
06:39 "I am inside else statement".
06:44 Let us summarize.
06:46 In this tutorial, we have learnt:
06:49 if and if-else conditional statements in Perl
06:53 using sample programs.
06:55 Here is an assignment for you:
06:57 Print “It is an open source language”
07:01 when the variable declared has value 'Perl'
07:04 otherwise, print “It's a proprietary language”.
07:08 Watch the video available at the following link.
07:11 It summarizes the Spoken Tutorial project.
07:15 If you do not have good bandwidth, you can download and watch it.
07:20 The Spoken Tutorial project team:
07:22 Conducts workshops using spoken tutorials.
07:26 Gives certificates to those who pass an online test.
07:31 For more details, please write to contact at spoken hyphen tutorial dot org.
07:37 "Spoken Tutorial" project is a part of the "Talk to a Teacher" project.
07:42 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
07:50 More information on this mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro.
08:00 Hope you enjoyed this Perl tutorial.
08:04 This is Amol Brahmankar, signing off.
08:06 Thanks for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Sandhya.np14