Ruby/C2/Control-Statements/Gujarati

From Script | Spoken-Tutorial
Revision as of 16:05, 17 July 2014 by Jyotisolanki (Talk | contribs)

Jump to: navigation, search


Time Narration
00:01 Welcome to the spoken tutorial on in Ruby. મા Control Statements પર ના સ્પોકન ટ્યુટોરીયલમા તમારુ સ્વાગત છે.
00:06 આ ટ્યુટોરીયલમા આપણે શીખીશું
00:08 if statement (ઇફ સ્ટેટમેંટ)
00:09 elsif statement (ઇફએલ્સ સ્ટેટમેંટ)
00:11 else (એલ્સ)
00:12 case statements (કેસ સ્ટેટમેંટ)
00:14 અહીં આપણે વાપરી રહ્યા છે
00:15 Ubuntu આવૃત્તિ 12.04
00:18 Ruby 1.9.3
00:21 આ ટ્યુટોરીયલ અનુસરવા માટે, તમે 'ઈન્ટરનેટ સાથે જોડાયેલા હોવા ખુબ જરૂરી છે.


00:24 તમને Linux ના commands, Terminal અને Text-editor. નું પણ જ્ઞાન હોવું જરૂરી છે.


00:30 જો નથી, તો સંબંધિત ટ્યુટોરિયલ્સ માટે, અમારી વેબસાઇટ જુઓ.
00:34 શરત કરવા પહેલા યાદ કરો કે આપણે “ttt” નામની ડિરેક્ટરી પહેલા બનાવી હતી.
00:38 Let's go to that directory. ચાલો તે ડિરેક્ટરી પર જઈએ.
00:41 પછી ruby hyphen tutorial control hyphen statements
00:47 હમણા તે ફોલ્ડર મા છીએ ચાલો આગળ વધીએ.
00:52 Ruby મા if statement માટે સિન્ટેક્સ નીચે પ્રમાણે છે:
00:56 if “condition” (ઇફ કન્ડીશન)
00:58 ruby code (રૂબી કોડ)
00:59 end (એન્ડ)


01:01 ચાલો ઉદાહરણ જોઈએ.
01:03 gedit' મા નવી ફાઈલ બનાવવી જે બસિક લેવલ ના 'Ruby tutorials મા બતાવ્યું.
01:08 if hyphen statement dot rb તેને નામ આપો
01:12 મારી પાસે if statement. ના ઉદાહરણ છે.


01:15 ટ્યુટોરીયલ અટકાવી તમે આ કોડ ટાઈપ કરી તેને ફરતે જી શકો છો.
01:19 આ ઉદાહરણ મા હું if statement ને ડીકલેર કરીશ.
01:23 પહેલા હું લોકલ વેરીએબલ my_num ડીકલેર કરીશ અને તેને વેલ્યુ 2345 આપીશ.
01:31 પછી હું if statement. ડીકલેર કરીશ.
01:34 if statement મા puts મેથડ ડીકલેર કરી છે જે આઉટપુટ આપશે.
01:39 if statement my_num ની વેલ્યુ 0 કરતા વધારે છે તે તપાસશે.
01:43 જો તે હશે તો નિર્દેશ કરાયેલ string. આઉટપુટ પ્રિન્ટ કરશે.
01:47 હવે ચાલો terminal પર પાછા જઈએ અને ટાઈપ કરો.
01:51 ruby space if hyphen statement dot rb
01:57 આઉટપુટ આ રીતે પ્રદશિત થાય છે “The value of my_num is greater than 0”.
02:02 આ આઉટપુટ if કન્ડીશન true. છે તે સાબિત કરે છે.
02:07 Ruby. મા હવે તમે પોતાના if statement લખવા માટે શમર્થ હોવા જોઈએ.
02:12 હવે આગળ if-else statement જોઈએ.
02:16 else માટે સિન્ટેક્સ વાપરીશું:


02:18 if “condition” (ઇફ કન્ડીશન)
02:19 ruby code (રૂબી કોડ)
02:20 else (એલ્સ)
02:21 ruby code (રૂબી કોડ)
02:22 end (એન્ડ)
02:24 Let us look at an example. ચાલો ઉદાહરણ જોઈએ.
02:26 Rubyના બેસિક લેવલના ટ્યુટોરીયલોમા બતાવ્યા પ્રમાણે gedit મા નવી ફાઈલ બનાઓ.


02:30 તેને if hyphen else hyphen statement dot rb નામ આપો.
02:37 મારી પાસે if-else statement. ના ઉદાહરણ છે.
02:40 ટ્યુટોરીયલ અટકાવી તમે આ કોડ ટાઈપ કરી તેને ફરતે જઈ શકો છો.
02:44 આ ઉદાહરણમા હું if-else statement ને ડીકલેર કરીશ.
02:48 પહેલા હું લોકલ વેરીએબલ my_num ડીકલેર કરીશ અને તેને વેલ્યુ -1 આપીશ.
02:55 પછી હું 'if' statement ડીકલેર કરીશ.
02:58 if statement my_num ની વેલ્યુ 0 કરતા વધારે છે તે તપાસશે.


03:03 જો તે હશે તો નિર્દેશ કરાયેલ string. આઉટપુટ પ્રિન્ટ કરશે.


03:06 જો નથી તો તે else સ્ટેટમેંટપર જશે.
03:10 અને તે અહી નિર્દેશ કરાયેલ string પ્રિન્ટ કરશે.
03:13 હવે ચાલો terminal પર પાછા જઈએ અને ટાઈપ કરો.
03:18 ruby space if hyphen else hyphen statement dot rb


03:26 અને આઉટપુટજુઓ.
03:27 આઉટપુટ આ ઇતે દશ્યમાન થયા છે. “The value of my_num is lesser than 0”.
03:32 આ બતાવે છે કે else statement એક્ઝીક્યુટ થાય છે.
03:35 Ruby. મા હવે તમે પોતાના if-else statement લખવા માટે શમર્થ હોવા જોઈએ.
03:41 હવે આગળ if-else statement જોઈએ.
03:45 elsif માટે સિન્ટેક્સ વાપરીશું:
03:48 if “condition” ruby code (ઇફ કન્ડીશન) (રૂબી કોડ)


03:50 elsif “condition” ruby code ( એલ્સઇફ કન્ડીશન) (રૂબી કોડ)


03:52 else ruby code (એલ્સ) (રૂબી કોડ)
03:54 end (એન્ડ)
03:55 ચાલો ઉદાહરણ જોઈએ.
03:58 Rubyના બેસિક લેવલના ટ્યુટોરીયલોમા બતાવ્યા પ્રમાણે gedit મા નવી ફાઈલ બનાઓ.


04:01 તેને નામ આપો if hyphen elsif hyphen statement dot rb


04:07 મારી પાસે if-elsif- statement ના ઉદાહરણ છે.


04:10 ટ્યુટોરીયલ અટકાવી તમે આ કોડ ટાઈપ કરી તેને ફરતે જઈ શકો છો.
04:14 આ ઉદાહરણમા હું 'if-elsif statement ને ડીકલેર કરીશ.
04:19 અહી પણ હું લોકલ વેરીએબલ my_num ડીકલેર કરીશ અને તેને વેલ્યુ -1 આપીશ.
04:25 પછી હું 'if' statement ડીકલેર કરીશ.
04:28 if statement my_num ની વેલ્યુ 0 કરતા વધારે છે તે તપાસશે.
04:32 જો તે હશે તો નિર્દેશ કરાયેલ string. આઉટપુટ પ્રિન્ટ કરશે.
04:35 જો તે true નહી હોય તો elsif સેક્શન માં જશે.
04:39 હવે આ my_num ની વેલ્યુ -1 છે કે તે તપાસસે.
04:43 જો તે true છે તો નિર્દેશ કરાયેલ string. પ્રિન્ટ કરશે
04:46 my_num ની વેલ્યુ ન તો 0 કરતા મોટી અને ન તો -1 જટલી છે તો તે else સેક્શન માં જશે.


04:54 પણ જ્યાર શુધી my_num = -1 વેલ્યુ રહેશે તે else block માં નહી જાય.
05:00 અને conditional statement. થી બહાર જશે
05:03 ચલો terminal પર પાછા જઈએ અને ટાઈપ કરો.
05:07 ruby space if hyphen elsif hyphen statement dot rb
05:15 અને આઉટપુટ જુઓ.
05:17 આઉટપુટ આ રીતે દ્રશ્યમાન થાય છે “The value of my_num is -1 and is lesser than 0”.
05:23 ચાલો આપણી ફાઈલ પર પાછા જઈએ અને my_num ની વેલ્યુ બદલીને 5 આપીએ.
05:29 ચાલો ટર્મિનલ પર કોડ સેવ અને એક્ઝીક્યુટ કરીએ.
05:35 તો હવે if condition ફૂલ્ફીલ્સ થયો છે અને નિર્દેશ કરાયેલ સ્ટ્રીંગ પ્રિન્ટ થઈ છે.
05:42 my_num ની વેલ્યુ એ 0 કરતા મોટી છે.
05:45 ચાલો આપણી ફાઈલ પર પાછા જઈએ અને my_num' ની વેલ્યુ બદલીને -5 આપીએ.
05:50 ચાલો ટર્મિનલ પર કોડ સેવ અને એક્ઝીક્યુટ કરીએ.


05:55 આ કિસ્સામા else કન્ડીશન ફૂલફિલ થાય છે અને else block મા puts સ્ટેટમેંટ એક્ઝીક્યુટ થશે.
06:03 Ruby. મા હવે તમે પોતાના if- elsif લખવા માટે શમર્થ હોવા જોઈએ.
06:08 હવે આગળ આપણે case statement જોશું.
06:12 case statement એ વિશિષ્ઠ સિલેકશન માટે control flow statement છે.
06:17 આ સ્ટેટમેંટ સમજવા માટે case statement નું સિન્ટેક્સ જોઈએ.
06:22 case વાપરવાનો સિન્ટેક્સ છે:
06:24 case variable (કેસ વેરીએબલ)
06:26 when “value 1” (વેન વેલ્યુ 1)
06:28 ruby code (રૂબી કોડ)
06:29 when “value 2” (વેન વેલ્યુ 2)
06:30 ruby code (રૂબી કોડ)
06:31 else (એલ્સ)
06:32 ruby code (રૂબી કોડ)


06:34 end (એન્ડ)
06:35 ચાલો ઉદાહરણ જોઈએ.
06:37 Ruby ના બેસિક લેવલના ટ્યુટોરીયલોમા બતાવ્યા પ્રમાણે gedit મા નવી ફાઈલ બનાઓ
06:41 તેને case hyphen statement dot rb નામ આપો.
06:44 મારી પાસે case statement.' ના ઉદાહરણ છે.


06:48 ટ્યુટોરીયલ અટકાવી તમે આ કોડ ટાઈપ કરી તેને ફરતે જઈ શકો છો.


06:52 આ ઉદાહરણમા હું case statement ને ડીકલેર કરીશ.
06:55 મારી પાસે print statement, છે જે ટર્મિનલ પર સવાલ પ્રિન્ટ કરશે.
07:01 પછી હું gets, ને કોલ કરશે જે standard input માં સિંગલ લાઈન ડેટા સ્વીકારશે.
07:09 પછી ઈનપુટ ડેટા મા હું new line characters વાપરીને chomp. કરીશ.
07:15 આ પરિણામને હું domain. નામના વેરીએબલમા અસાઈન કરીશ.


07:18 પછી હું કેસ સ્ટેટમેંટ ડીકલેર કરીશ.
07:22 તેમાં હું when statement ડીકલેર કરીશ.


07:25 આ અહી આપેલી સ્ટ્રીંગ અને domain. ની વેલ્યુ સરખી છે કે નહી તે તપાસે છે.
07:30 પ્રથમ domain ની વેલ્યુ “UP”. છે કે તે તપાસસે.
07:34 આવું થાય તો તે “Uttar Pradesh” પ્રિન્ટ કરશે અને કેસ સ્ટેટમેંટ થી બહાર આવશે.
07:39 If domain is not “UP”, it checks whether the value of domain is “MP”.
07:44 If it is so, it will print out “Madhya Pradesh” and so on.
07:48 It will continue checking the value of domain if no match was found so far.
07:53 At this point it will encounter the else statement
07:56 as none of the above conditions were true.
07:59 It will subsequently execute the ruby code that follows the else declaration.
08:03 It will print “Unknown” as per our example.
08:07 Now, save the file, switch to the terminal and type


08:11 ruby space case hyphen statement dot rb.
08:18 “Enter the state you live in:” will be displayed on the terminal.
08:22 Type in “UP” and see the output.
08:25 The output will display “Uttar Pradesh”.
08:28 Next execute the Ruby file again, like before.


08:31 This time at the prompt type “KL” and see the output.
08:36 It will print “Kerala”.
08:38 Next execute the file one more time.
08:41 This time at the prompt type in “TN” and see the output.
08:47 It will print “Unknown”.
08:50 This is because none of the cases were satisfied. So, the default else statement is executed.
08:58 You should now be able to write your own case-statements in Ruby.
09:03 This brings us to the end of this Spoken Tutorial.


09:07 Let's summarize.
09:08 In this tutorial we have learnt to use


09:10 if statement
09:12 else construct
09:13 if-elsif and
09:15 case statements
09:17 As an assignment :
09:18 Write a Ruby program :


09:20 that prompts a user to enter a number


09:23 then use the appropriate control-statement
09:26 to check if the number is a multiple of 2
09:29 if it is, then print “The number entered is a multiple of 2”
09:35 if not, it should check if it is a multiple of 3
09:38 if it is, then print “The number entered is a multiple of 3”
09:43 if not, it should check if it a multiple of 4
09:47 if it is, then print “The number entered is a multiple of 4”
09:51 if not, it should print “The number is not a multple of 2, 3 or 4”
09:56 Watch the video available at the following link.
10:00 It summarises the Spoken Tutorial project.
10:03 If you do not have good bandwidth, you can download and watch it.
10:07 The Spoken Tutorial Project Team :
10:09 Conducts workshops using spoken tutorials
10:13 Gives certificates to those who pass an online test
10:16 For more details, please write to contact@spoken-tutorial.org
10:21 Spoken Tutorial Project is a part of the Talk to a Teacher project.
10:26 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
10:32 More information on this Mission is available at spoken hyphen tutorial dot org slash NMEICT hyphen Intro
10:41 This is Anjani Nair signing off. Thanks for watching.



Contributors and Content Editors

Jyotisolanki, PoojaMoolya