Difference between revisions of "Ruby/C3/for-and-each-Looping-Statements/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 2: Line 2:
  
 
{| border=1
 
{| border=1
|| '''Time'''
+
|| ''Time'''
 
|| '''Narration'''
 
|| '''Narration'''
  
 
|-
 
|-
|  00:01
+
|  00.01
| રૂબીમા  '''for''' અને  '''each Loops''' ટ્યુટોરીયલમા તમારું સ્વાગત છે.  
+
| Welcome to the tutorial on '''for''' and '''each Loops''' in Ruby.  
  
 
|-
 
|-
| 00:05
+
| 00.05
| આ ટ્યુટોરીયલમાં આપણે શીખીશું.
+
| In this tutorial we will learn
  
 
|-
 
|-
| 00:07
+
| 00.07
| ''' “loop” ''' (લૂપ) એટલે શું.
+
| Meaning of the term ''' “loop” '''
  
 
|-
 
|-
| 00:08
+
| 00.08
|'''Ruby ''' મા વિવિધ પ્રકારના લૂપ.
+
|The different kinds of loops in '''Ruby '''
  
 
|-
 
|-
| 00:11
+
| 00.11
| ''' “for” ''' લૂપનો વપરાશ અને 
+
| Usage of ''' “for” ''' loop and
  
 
|-
 
|-
|  00:12
+
|  00.12
| ''' “each” ''' લૂપનો વપરાશ.
+
|Usage of ''' “each” ''' looping construct
  
 
|-
 
|-
|  00:14
+
|  00.14
|અહી આપણે વાપરી રહ્યા છે.
+
|Here we are using
  
 
|-
 
|-
|  00:16
+
|  00.16
|  ''' Ubuntu''' આવૃત્તિ 12.04  
+
|  ''' Ubuntu''' version 12.04  
  
 
|-
 
|-
| 00:19
+
| 00.19
 
|''' Ruby '''1.9.3  
 
|''' Ruby '''1.9.3  
  
 
|-
 
|-
| 00:22
+
| 00.22
|આ ટ્યુટોરીયલ અનુસરવા માટે, તમારી પાસે '' ઇન્ટરનેટ '' 'કનેક્શન હોવું જરૂરી છે .
+
|To follow this tutorial, you must have ''' Internet''' Connection.
 
    
 
    
  
 
|-
 
|-
|  00:25
+
|  00.25
| આ ટ્યુટોરીયલ અનુસરવા તમને ''''Linux''' મા '''commands''', ''' Terminal''' અને  ''' Text-editor.''' નું જ્ઞાન હોવું જોઈએ.
+
| You must also have knowledge of '''Linux'''  commands, ''' Terminal''' and ''' Text-editor.'''
  
  
  
 
|-
 
|-
| 00:30
+
| 00.30
|જો નથી , તો સંબંધિત ટ્યુટોરિયલ્સ માટે, અમારી વેબસાઇટ જુઓ.  
+
|If not, for relevant tutorials, please visit our website.  
 
+
  
 
|-
 
|-
|  00:34
+
|  00.34
|   '''રૂબી મા ''' “loop” ''' એ શું તરીકે ઓળખવામાં આવે છે તે હું સમજાવીશ.
+
| Now let me explain what is referred to as a ''' “loop” ''' in '''Ruby. '''
  
 
|-
 
|-
| 00:38
+
| 00.38
|લૂપ એ કમાંડ  અથવા કમાંડ નો સમૂહ છે વખત એક નિશ્ચિત સમયે  એક્ઝિક્યુટથયા છે.
+
|A '''loop''' is a command or set of commands that are executed a fixed number of times.  
  
 
|-
 
|-
| 00:44
+
| 00.44
|''' Ruby''' નીચેના મુખ્ય લૂપીંગ સ્ટેટમેંટ છે.  
+
|''' Ruby''' has the following main looping statements.  
  
 
|-
 
|-
| 00:47
+
| 00.47
|'''for''' (ફોર)
+
|'''for'''
  
 
|-
 
|-
| 00:48
+
| 00.48
| '''each ''' (ઈચ)
+
| '''each '''
  
 
|-
 
|-
| 00:49
+
| 00.49
|''' while''' (વાઇલ)
+
|''' while'''
  
 
|-
 
|-
|  00:49
+
|  00.49
| '''until''' (અનટિલ)
+
| '''until'''
  
 
|-
 
|-
| 00:50
+
| 00.50
|આ ટ્યુટોરીયલ માં આપણે  શીખીશું  '''for''' અને  ''' each''' લૂપીંગ ના બંધારણો.
+
|In this tutorial we will learn how to use the '''for''' and ''' each''' looping constructs.  
  
 
|-
 
|-
| 00:55
+
| 00.55
|આપણે શરૂ કરતા પહેલા, હોમ ડિરેક્ટરીમાં આપેલ ફોલ્ડર્સ બનાવો,
+
| Before we begin, please create the following folders in your home directory,  
  
 
|-
 
|-
| 01:02
+
| 01.02
 
| ttt,  ruby hyphen tutorial, looping hyphen statements.  
 
| ttt,  ruby hyphen tutorial, looping hyphen statements.  
  
 
|-
 
|-
| 01:07
+
| 01.07
| કૃપા કરી  ત્યાં બતાવ્યા પ્રમાણે  સબ ફોલ્ડર બનાવો .
+
| Please create the sub folders as mentioned there
  
 
|-
 
|-
| 01:11
+
| 01.11
|હવે આપણે જરૂરી ફોલ્ડરો બનાવ્યા છે.
+
|Now we have created the requisite folders.  
  
 
|-
 
|-
| 01:13
+
| 01.13
|ચાલો આગળ વધીએ.
+
|Let's move ahead.  
  
 
|-
 
|-
| 01:15
+
| 01.15
| ''' Ruby''' મા  ''' “for” ''' લૂપનું સિન્ટેક્સ નીચે પ્રમાણે છે:  
+
|The syntax of the ''' “for” ''' loop in ''' Ruby''' is as follows:  
  
  
 
|-
 
|-
|  01:19
+
|  01.19
 
| ''' for “variable” in “a collection of objects” '''
 
| ''' for “variable” in “a collection of objects” '''
  
  
 
|-
 
|-
|  01:22
+
|  01.22
 
|''' ruby code '''
 
|''' ruby code '''
  
 
|-
 
|-
|  01:23
+
|  01.23
 
| ''' end '''
 
| ''' end '''
  
 
|-
 
|-
| 01:25
+
| 01.25
| આપણે  ઉદાહરણ સાથે તે સમજવાનો  પ્રયાસ કરીએ.
+
| Let us try to understand it with an example.  
  
 
|-
 
|-
|  01:28
+
|  01.28
| '''gedit''' મા એક નવી ફાઈલ બનાવોજે  ''' Ruby''' ના બેસિક લેવલના ટ્યુટોરિયલ્સમા છે.  
+
| Create a new file in '''gedit''' as shown in the basic level ''' Ruby''' tutorials.  
  
 
|-
 
|-
| 01:32
+
| 01.32
|અને તેને  ''' “for hyphen loop dot rb” ''' નામ આપો.
+
|And name it ''' “for hyphen loop dot rb” '''
  
  
 
|-
 
|-
| 01:36
+
| 01.36
| મેં પહેલા જ  ''' “for” ''' લૂપનું ઉદાહરણ ટીયર કર્યું છે.  
+
|I already have a working example of the ''' “for” ''' loop.  
  
 
|-
 
|-
| 01:39
+
| 01.39
|આ ઉદાહરણ સમજ્યા પછી તમે કોડ ટાઈપ કરી શકો છો.  
+
|You can type the code as we go through this example.  
  
 
|-
 
|-
|  01:44
+
|  01.44
| ''' “for” ''' લૂપને આ ઉદાહરણમા ડીકલેર કર્યું છે.  
+
| I have declared a ''' “for” ''' loop in this example.  
  
 
|-
 
|-
| 01:47
+
| 01.47
|  We have a set of નુંમ્બેર્સ આપની પસે  '''1 થી  20''' નંબર નો સમૂહ છે..  
+
|  We have a set of numbers 1 to 20.  
  
 
|-
 
|-
| 01:50
+
| 01.50
| ''' “for” ''' લૂપમા “i” કહેવાતા વેરીએબલ ને આપણે ડીકલેર કર્યું છે .  
+
| We declare a variable called “i” within the ''' “for” ''' loop.  
  
  
 
|-
 
|-
|  01:55
+
|  01.55
|The variable “i” એ વેરીએબલ ''' 1 થી  20. ''' ના સમૂહ માંથી  પ્રથમ એલિમેન્ટ થી શરૂઆત કરશે.  
+
|The variable “i” gets initialized to the first element in the set of numbers 1 to 20.  
  
 
|-
 
|-
|  02:00
+
|  02.00
| The ''' “for” '''  લૂપ  '''1 થી  20''' ના સમૂહને ડીકલેર કરવા  પ્રત્યેક એલિમેન્ટને  ઇટરેટ કરેશે.  
+
| The ''' “for” '''  loop declaration causes the code to iterate over each element in the set 1 to 20.  
  
 
|-
 
|-
|  02:07
+
|  02.07
|''' “for” ''' લૂપ અંતર્ગત ડીકલેર કરાયેલું  ''' “puts” ''' મેથડ આઉટપુટ બનાવવા માટે જવાબદાર છે.  
+
| The ''' “puts” ''' method declared within the ''' “for” ''' loop is responsible for generating the output.  
  
  
 
|-
 
|-
| 02:14
+
| 02.14
|હવે ટર્મિનલ ખોલો અને ટાઈપ કરો 
+
|Now open the ''' terminal''' and type
  
 
|-
 
|-
|  02:17
+
|  02.17
| ''' ruby space  for hyphen loop dot rb ''' અને આઉટપુટ જુઓ.
+
| ''' ruby space  for hyphen loop dot rb ''' and see the output
  
 
|-
 
|-
| 02:22
+
| 02.22
| '''1 થી  20''' ના નંબર '''array''' આઉટપુટ હશે.  
+
|The output will be an '''array''' of numbers 1 to 20.  
  
 
|-
 
|-
|  02:26
+
|  02.26
 
| In this example, we declared a  ''' “for”''' loop for an inclusive range.  
 
| In this example, we declared a  ''' “for”''' loop for an inclusive range.  
  
 
|-
 
|-
| 02:31
+
| 02.31
 
| It included all numbers from 1 to 20.  
 
| It included all numbers from 1 to 20.  
  
 
|-
 
|-
| 02:35
+
| 02.35
 
| Next,  we shall look at implementing the ''' “for”''' loop for a non-inclusive range.  
 
| Next,  we shall look at implementing the ''' “for”''' loop for a non-inclusive range.  
  
 
|-
 
|-
| 02:41
+
| 02.41
 
|Continue to type the next part of the code.  
 
|Continue to type the next part of the code.  
  
 
|-
 
|-
| 02:44
+
| 02.44
 
|Non-inclusive means it will not include the last element in the collection of objects.  
 
|Non-inclusive means it will not include the last element in the collection of objects.  
  
 
|-
 
|-
| 02:49
+
| 02.49
 
|Here ''' “for”''' loop is implemented for a non-inclusive range of numbers 1 to 20.  
 
|Here ''' “for”''' loop is implemented for a non-inclusive range of numbers 1 to 20.  
  
 
|-
 
|-
|  02:55
+
|  02.55
 
| You will notice shortly that the number 20 will not be printed in the output.  
 
| You will notice shortly that the number 20 will not be printed in the output.  
  
 
|-
 
|-
| 02:59
+
| 02.59
 
|The last digit does not get included when you have 3 dots between numbers.  
 
|The last digit does not get included when you have 3 dots between numbers.  
  
 
|-
 
|-
| 03:04
+
| 03.04
 
| Now open the ''' terminal''' and type ''' ruby space for hyphen loop dot rb'''
 
| Now open the ''' terminal''' and type ''' ruby space for hyphen loop dot rb'''
  
 
|-
 
|-
| 03:13
+
| 03.13
 
|and see the output.  
 
|and see the output.  
  
 
|-
 
|-
| 03:17
+
| 03.17
 
|The output will still be an ''' array''' of numbers but will not include the number 20.  
 
|The output will still be an ''' array''' of numbers but will not include the number 20.  
  
  
 
|-
 
|-
| 03:22
+
| 03.22
 
| Now, you should be capable enough to write your own ''' “for”'''  loop.  
 
| Now, you should be capable enough to write your own ''' “for”'''  loop.  
  
 
|-
 
|-
| 03:27
+
| 03.27
 
|The syntax of the ''' “each”''' loop in ''' Ruby''' is as follows:  
 
|The syntax of the ''' “each”''' loop in ''' Ruby''' is as follows:  
  
 
|-
 
|-
|  03:31
+
|  03.31
 
| ''' “a collection of objects” dot each do item '''
 
| ''' “a collection of objects” dot each do item '''
  
 
|-
 
|-
|  03:36
+
|  03.36
 
| ''' ruby code end'''
 
| ''' ruby code end'''
  
 
|-
 
|-
|  03:38
+
|  03.38
 
|Let us try to understand it with an example.  
 
|Let us try to understand it with an example.  
  
  
 
|-
 
|-
|  03:42
+
|  03.42
 
| Create a new file in '''gedit''' as shown in the basic level '''Ruby''' tutorials.  
 
| Create a new file in '''gedit''' as shown in the basic level '''Ruby''' tutorials.  
  
 
|-
 
|-
| 03:46
+
| 03.46
 
|And name it '''each hyphen loop dot rb'''
 
|And name it '''each hyphen loop dot rb'''
  
 
|-
 
|-
|  03:50
+
|  03.50
 
|I already have a working example of the '''each''' loop.  
 
|I already have a working example of the '''each''' loop.  
  
 
|-
 
|-
|  03:53
+
|  03.53
 
|You can type the code as we go through this example.  
 
|You can type the code as we go through this example.  
  
 
|-
 
|-
| 03:58
+
| 03.58
 
|I have declared an '''each''' loop in this example.  
 
|I have declared an '''each''' loop in this example.  
  
 
|-
 
|-
|  04:03
+
|  04.03
 
|  We have a set of numbers 1 to 20.  
 
|  We have a set of numbers 1 to 20.  
  
 
|-
 
|-
| 04:06
+
| 04.06
 
|We declare a variable called “i” within the '''each''' loop.  
 
|We declare a variable called “i” within the '''each''' loop.  
  
  
 
|-
 
|-
| 04:11
+
| 04.11
 
| The “i” variable gets initialized to the first element in the set of numbers 1 to 20.  
 
| The “i” variable gets initialized to the first element in the set of numbers 1 to 20.  
 
   
 
   
  
 
|-
 
|-
| 04:17
+
| 04.17
 
|The '''each''' loop declaration causes the code to iterate over each element in the set 1 to 20.  
 
|The '''each''' loop declaration causes the code to iterate over each element in the set 1 to 20.  
  
 
|-
 
|-
| 04:23
+
| 04.23
 
|The ''' puts''' method declared within the ''' each'''  is responsible for generating the output.  
 
|The ''' puts''' method declared within the ''' each'''  is responsible for generating the output.  
  
 
|-
 
|-
| 04:30
+
| 04.30
 
|Now open the ''' terminal''' and type ''' ruby space each hyphen loop dot rb '''
 
|Now open the ''' terminal''' and type ''' ruby space each hyphen loop dot rb '''
  
 
|-
 
|-
|  04:39
+
|  04.39
 
| and see the output.  
 
| and see the output.  
  
  
 
|-
 
|-
| 04:43
+
| 04.43
 
|The output will be an array of numbers 1 to 20.  
 
|The output will be an array of numbers 1 to 20.  
  
  
 
|-
 
|-
|  04:46
+
|  04.46
 
| In the above example we declared an ''' each''' loop for an inclusive range.  
 
| In the above example we declared an ''' each''' loop for an inclusive range.  
  
  
 
|-
 
|-
|  04:51
+
|  04.51
 
|It included all numbers from 1 to 20.  
 
|It included all numbers from 1 to 20.  
  
 
|-
 
|-
| 04:54
+
| 04.54
 
| Next we shall look at implementing the '''each''' loop for a non-inclusive range.  
 
| Next we shall look at implementing the '''each''' loop for a non-inclusive range.  
  
 
|-
 
|-
| 05:00
+
| 05.00
 
|Continue to type this part of the code.  
 
|Continue to type this part of the code.  
  
 
|-
 
|-
| 05:04
+
| 05.04
 
| Non-inclusive means it will not include the last element in the collection of objects.  
 
| Non-inclusive means it will not include the last element in the collection of objects.  
  
 
|-
 
|-
| 05:10
+
| 05.10
 
| Here an '''each''' loop is implemented for a non-inclusive range of numbers 1 to 20.  
 
| Here an '''each''' loop is implemented for a non-inclusive range of numbers 1 to 20.  
  
  
 
|-
 
|-
| 05:16
+
| 05.16
 
| You will notice shortly that the number 20 will not be printed in the output.  
 
| You will notice shortly that the number 20 will not be printed in the output.  
  
 
|-
 
|-
| 05:20
+
| 05.20
 
| The last digit does not get included when you have 3 dots between numbers.  
 
| The last digit does not get included when you have 3 dots between numbers.  
  
 
|-
 
|-
| 05:25
+
| 05.25
 
|Now open the '''terminal''' and type '''ruby space each hyphen loop dot rb'''
 
|Now open the '''terminal''' and type '''ruby space each hyphen loop dot rb'''
  
 
|-
 
|-
| 05:34
+
| 05.34
 
| and see the output.  
 
| and see the output.  
  
 
|-
 
|-
| 05:39
+
| 05.39
 
|Now you should be capable enough to write your own '''each''' loop.  
 
|Now you should be capable enough to write your own '''each''' loop.  
  
 
|-
 
|-
| 05:44
+
| 05.44
 
|How would we determine which looping construct to choose?  
 
|How would we determine which looping construct to choose?  
  
 
|-
 
|-
| 05:48
+
| 05.48
 
|Let us try to recall the '''for''' loop construct.  
 
|Let us try to recall the '''for''' loop construct.  
 
   
 
   
  
 
|-
 
|-
| 05:53
+
| 05.53
 
|In the first example, we iterated over a set of numbers from 1 to 20 using '''for'''.  
 
|In the first example, we iterated over a set of numbers from 1 to 20 using '''for'''.  
  
 
|-
 
|-
| 05:59
+
| 05.59
 
| Execute ''' ruby space for hyphen loop dot rb''' in your terminal see the output.   
 
| Execute ''' ruby space for hyphen loop dot rb''' in your terminal see the output.   
  
 
|-
 
|-
|06:08
+
|06.08
 
| Now look at the code in '''gedit.'''  
 
| Now look at the code in '''gedit.'''  
  
 
|-
 
|-
| 06:11
+
| 06.11
 
|When you invoke the '''for loop''', '''Ruby''' is actually calling the '''each''' method behind the scenes.  
 
|When you invoke the '''for loop''', '''Ruby''' is actually calling the '''each''' method behind the scenes.  
  
 
|-
 
|-
| 06:16
+
| 06.16
 
|And calling '''each''' or '''for''' will generate the same output.  
 
|And calling '''each''' or '''for''' will generate the same output.  
  
 
|-
 
|-
| 06:21
+
| 06.21
 
|Since the call to '''for''' in turn calls ''' each''', it is preferable to use the '''each''' loop instead.   
 
|Since the call to '''for''' in turn calls ''' each''', it is preferable to use the '''each''' loop instead.   
  
 
|-
 
|-
|  06:28
+
|  06.28
 
| This brings us to the end of this Spoken Tutorial.  
 
| This brings us to the end of this Spoken Tutorial.  
  
  
 
|-
 
|-
| 06:30
+
| 06.30
 
|Let's summarize.  
 
|Let's summarize.  
  
  
 
|-
 
|-
| 06:32
+
| 06.32
 
|In this tutorial we have learnt
 
|In this tutorial we have learnt
  
 
|-
 
|-
|  06:33
+
|  06.33
 
|  Usage of ''' for''' loop  
 
|  Usage of ''' for''' loop  
 
   
 
   
 
|-
 
|-
| 06:35
+
| 06.35
 
|Usage of  '''each''' construct  
 
|Usage of  '''each''' construct  
  
 
|-
 
|-
| 06:38
+
| 06.38
 
|Reasoning behind using '''each''' instead of '''for'''  
 
|Reasoning behind using '''each''' instead of '''for'''  
  
 
|-
 
|-
| 06:41
+
| 06.41
 
|Examples of using the above looping constructs  
 
|Examples of using the above looping constructs  
  
 
|-
 
|-
| 06:45
+
| 06.45
 
| As an assignment  
 
| As an assignment  
  
 
|-
 
|-
| 06:47
+
| 06.47
 
|Write a ruby program using the appropriate loop construct  
 
|Write a ruby program using the appropriate loop construct  
  
 
|-
 
|-
| 06:50
+
| 06.50
 
|to create an output of even numbers from a set of numbers, say 1 to 20
 
|to create an output of even numbers from a set of numbers, say 1 to 20
  
  
 
|-
 
|-
|  06:56
+
|  06.56
 
|  Watch the video available at the following link.
 
|  Watch the video available at the following link.
  
 
|-
 
|-
| 07:00
+
| 07.00
 
|It summarises the Spoken Tutorial project.
 
|It summarises the Spoken Tutorial project.
  
 
|-
 
|-
| 07:03
+
| 07.03
 
|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:08
+
|  07.08
 
|  The Spoken Tutorial Project Team :
 
|  The Spoken Tutorial Project Team :
  
 
|-   
 
|-   
| 07:11
+
| 07.11
 
|Conducts workshops using spoken tutorials  
 
|Conducts workshops using spoken tutorials  
  
 
|-
 
|-
|07:14
+
|07.14
 
|Gives certificates to those who pass an online test  
 
|Gives certificates to those who pass an online test  
  
 
|-
 
|-
| 07:18
+
| 07.18
 
|For more details, please write to contact@spoken-tutorial.org
 
|For more details, please write to contact@spoken-tutorial.org
  
 
|-
 
|-
|  07:23
+
|  07.23
 
|  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:26
+
| 07.26
 
|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:33
+
| 07.33
 
|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
  
 
|-
 
|-
| 07:41
+
| 07.41
 
| This is Anjana Nair signing off. Thank you
 
| This is Anjana Nair signing off. Thank you
  
 
|}
 
|}

Revision as of 14:50, 22 July 2014


Time' Narration
00.01 Welcome to the tutorial on for and each Loops in Ruby.
00.05 In this tutorial we will learn
00.07 Meaning of the term “loop”
00.08 The different kinds of loops in Ruby
00.11 Usage of “for” loop and
00.12 Usage of “each” looping construct
00.14 Here we are using
00.16 Ubuntu version 12.04
00.19 Ruby 1.9.3
00.22 To follow this tutorial, you must have Internet Connection.


00.25 You must also have knowledge of Linux commands, Terminal and Text-editor.


00.30 If not, for relevant tutorials, please visit our website.
00.34 Now let me explain what is referred to as a “loop” in Ruby.
00.38 A loop is a command or set of commands that are executed a fixed number of times.
00.44 Ruby has the following main looping statements.
00.47 for
00.48 each
00.49 while
00.49 until
00.50 In this tutorial we will learn how to use the for and each looping constructs.
00.55 Before we begin, please create the following folders in your home directory,
01.02 ttt, ruby hyphen tutorial, looping hyphen statements.
01.07 Please create the sub folders as mentioned there
01.11 Now we have created the requisite folders.
01.13 Let's move ahead.
01.15 The syntax of the “for” loop in Ruby is as follows:


01.19 for “variable” in “a collection of objects”


01.22 ruby code
01.23 end
01.25 Let us try to understand it with an example.
01.28 Create a new file in gedit as shown in the basic level Ruby tutorials.
01.32 And name it “for hyphen loop dot rb”


01.36 I already have a working example of the “for” loop.
01.39 You can type the code as we go through this example.
01.44 I have declared a “for” loop in this example.
01.47 We have a set of numbers 1 to 20.
01.50 We declare a variable called “i” within the “for” loop.


01.55 The variable “i” gets initialized to the first element in the set of numbers 1 to 20.
02.00 The “for” loop declaration causes the code to iterate over each element in the set 1 to 20.
02.07 The “puts” method declared within the “for” loop is responsible for generating the output.


02.14 Now open the terminal and type
02.17 ruby space for hyphen loop dot rb and see the output
02.22 The output will be an array of numbers 1 to 20.
02.26 In this example, we declared a “for” loop for an inclusive range.
02.31 It included all numbers from 1 to 20.
02.35 Next, we shall look at implementing the “for” loop for a non-inclusive range.
02.41 Continue to type the next part of the code.
02.44 Non-inclusive means it will not include the last element in the collection of objects.
02.49 Here “for” loop is implemented for a non-inclusive range of numbers 1 to 20.
02.55 You will notice shortly that the number 20 will not be printed in the output.
02.59 The last digit does not get included when you have 3 dots between numbers.
03.04 Now open the terminal and type ruby space for hyphen loop dot rb
03.13 and see the output.
03.17 The output will still be an array of numbers but will not include the number 20.


03.22 Now, you should be capable enough to write your own “for” loop.
03.27 The syntax of the “each” loop in Ruby is as follows:
03.31 “a collection of objects” dot each do item
03.36 ruby code end
03.38 Let us try to understand it with an example.


03.42 Create a new file in gedit as shown in the basic level Ruby tutorials.
03.46 And name it each hyphen loop dot rb
03.50 I already have a working example of the each loop.
03.53 You can type the code as we go through this example.
03.58 I have declared an each loop in this example.
04.03 We have a set of numbers 1 to 20.
04.06 We declare a variable called “i” within the each loop.


04.11 The “i” variable gets initialized to the first element in the set of numbers 1 to 20.


04.17 The each loop declaration causes the code to iterate over each element in the set 1 to 20.
04.23 The puts method declared within the each is responsible for generating the output.
04.30 Now open the terminal and type ruby space each hyphen loop dot rb
04.39 and see the output.


04.43 The output will be an array of numbers 1 to 20.


04.46 In the above example we declared an each loop for an inclusive range.


04.51 It included all numbers from 1 to 20.
04.54 Next we shall look at implementing the each loop for a non-inclusive range.
05.00 Continue to type this part of the code.
05.04 Non-inclusive means it will not include the last element in the collection of objects.
05.10 Here an each loop is implemented for a non-inclusive range of numbers 1 to 20.


05.16 You will notice shortly that the number 20 will not be printed in the output.
05.20 The last digit does not get included when you have 3 dots between numbers.
05.25 Now open the terminal and type ruby space each hyphen loop dot rb
05.34 and see the output.
05.39 Now you should be capable enough to write your own each loop.
05.44 How would we determine which looping construct to choose?
05.48 Let us try to recall the for loop construct.


05.53 In the first example, we iterated over a set of numbers from 1 to 20 using for.
05.59 Execute ruby space for hyphen loop dot rb in your terminal see the output.
06.08 Now look at the code in gedit.
06.11 When you invoke the for loop, Ruby is actually calling the each method behind the scenes.
06.16 And calling each or for will generate the same output.
06.21 Since the call to for in turn calls each, it is preferable to use the each loop instead.
06.28 This brings us to the end of this Spoken Tutorial.


06.30 Let's summarize.


06.32 In this tutorial we have learnt
06.33 Usage of for loop
06.35 Usage of each construct
06.38 Reasoning behind using each instead of for
06.41 Examples of using the above looping constructs
06.45 As an assignment
06.47 Write a ruby program using the appropriate loop construct
06.50 to create an output of even numbers from a set of numbers, say 1 to 20


06.56 Watch the video available at the following link.
07.00 It summarises the Spoken Tutorial project.
07.03 If you do not have good bandwidth, you can download and watch it.
07.08 The Spoken Tutorial Project Team :
07.11 Conducts workshops using spoken tutorials
07.14 Gives certificates to those who pass an online test
07.18 For more details, please write to contact@spoken-tutorial.org
07.23 Spoken Tutorial Project is a part of the Talk to a Teacher project.
07.26 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
07.33 More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
07.41 This is Anjana Nair signing off. Thank you

Contributors and Content Editors

Jyotisolanki, PoojaMoolya, Pratik kamble, Sandhya.np14