Difference between revisions of "C-and-C++/C3/Loops/Gujarati"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 228: Line 228:
 
|-
 
|-
 
| 03.06
 
| 03.06
|Here we check whether x is less than or equal to 10 which means the values of x will be from 0 to 10
+
અહી આપણે તપાસ કરીએ છીએ કે  '''x''' એ  '''10''' જેટલી અથવા એ કરતા ઓછી કે નહી એટલે કે  x ની વેલ્યુ''' 0 થી  10'''સુધી રહેશે.
  
  
 
|-
 
|-
 
| 03.15
 
| 03.15
|Then we  add y plus x (i.e) 0 plus 0 we get 0.
+
|ત્યારબાદ આપણે y plus x ઉમેરીએ છીએ એટલેકે 0 plus 0 આપણે  0 મળે છે .
  
 
|-
 
|-
 
| 03.22
 
| 03.22
| We print the value of y, here we get 0.  
+
| આપણે  y ની વેલ્યુ પ્રિન્ટ કરીએ છીએ અહી આપણને ''' 0'''મળે છે.  
  
 
|-
 
|-
 
| 03.27
 
| 03.27
| Then x is incremented which means now the value of x will be 1
+
| હવે  x ને વધારવા માં આવે છે જેનો અર્થ એ છે કે હવે x ની વેલ્યુ  1 રહેશે.
 +
 
 
|-
 
|-
 
| 03.33
 
| 03.33

Revision as of 10:06, 2 April 2014

Time Narration


00.01 Loops in C and C++ પરનાં સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે.
00.06 આ ટ્યુટોરીયલમાં આપણે શીખીશું,
00.09 for loop,
00.10 while loop અને
00.12 do…while loop.
00.13 આપણે આ અમુક ઉદાહરણો ના મદદથી કરીશું.
00.17 આપણે અમુક સામાન્ય એરરો અને તેમનાં ઉપાયો પણ જોઈશું.
00.21 આ ટ્યુટોરીયલને રેકોર્ડ કરવા માટે, હું વાપરી રહ્યી છું
00.24 ઉબુન્ટુ ઓપરેટીંગ સીસ્ટમ આવૃત્તિ 11.04.
00.28 'gcc અને g++ કમ્પાઈલર આવૃત્તિ 4.6.1
00.34 ચાલો loops ના પરીચય સાથે શરૂઆત કરીએ .
00.38 Loops એકંદરે સૂચનાઓના સમુહને એક્ઝેક્યુટ કરવા માટે ઉપયોગી છે.
00.44 હેતુ પર આધાર રાખીને તેને ત્રણ પ્રકારોમાં વિભાજીત કરવામાં આવેલ છે:
00.48 while loop


00.49 do…..while loop અને
00.51 for loop
00.52 ચાલો પ્રથમ while loopથી શરૂઆત કરીએ.
00.56 A while loop કન્ડીશન ને શરૂઆત માં ચકાસે છે.
01.00 બંધારણ છે
01.01 while ( condition )
01.03 કૌંસમાં સ્ટેટમેંટ બ્લોક
01.07 હવે do….while loop પર જઈએ
01.09 do..while loopકન્ડીશન વેલીડેટથયી શકે તે પહેલા ઓછા માં ઓછું એક વખત એક્ઝેક્યુટ કરવામાં આવે છે .
01.15 બંધારણ છે
01.17 do કૌંસમાં સ્ટેટમેંટ બ્લોક
01.20 કૌંસ પછીથી whileકન્ડીશન
01.23 તમે જોઈ શકો છો કન્ડીશન અંતમાં પસંદ કરેલ છે.
01.27 હવે ચાલો while loop અને do...while loop પર એક ઉદાહરણ જોઈએ.
01.32 મેં એડિટર પર પહેલેથી જ કોડ ટાઈપ કર્યો છે.
01.35 ચાલો તે ખોલીએ.
01.37 નોંધ લો કે આપણી ફાઈલનું નામ while.c.છે.
01.41 આજે આપણે 'while loopના ઉપયોગથી પ્રથમ 10 ક્રમાંકો ને ઉમેરવાનું શીખવા જઈ રહ્યા છે .
01.47 ચાલો હું કોડ સમજાવુ.
01.49 આ આપણી હેડર ફાઈલ છે.
01.51 'main function અંતર્ગત આપણે બે ઈંટીજર વેરીએબલો x' અને y જાહેર કર્યા છે અને 0 પર ઈનીશલાઈઝ કર્યું છે.


01.59 આ આપણું while loop છે.
02.02 'while loopની કન્ડીશન છે x is less than or equal to 10.


02.06 અહી x ની વેલ્યુ yની વેલ્યુ માં ઉમેરાય છે.


02.10 ઉમેરા પછીથી પ્રાપ્ત થયેલ વેલ્યુ y માં સંગ્રહિત થાય છે.
02.15 ત્યારબાદ આપણે yની વેલ્યુ ને પ્રિન્ટ કરીએ છીએ.
02.18 અહી ' x એ વધારે કરેલ છે.
02.20 એનો અર્થ એ છે કે વેરીએબલ xએ એક અંક વધારો કરેલ છે.
02.25 અને આ આપણું return statement છે.
02.27 ચાલો હવે પ્રોગ્રામ એક્ઝેક્યુટ કરીએ.
02.30 તમારા કીબોર્ડ પર Ctrl, Alt અને T કી એકસાથે દાબીને, ટર્મીનલ વિન્ડો ખોલો.
02.39 ટાઈપ કરો gcc space while dot c space hyphen o space while
02.45 Enter દબાવો


02.47 ટાઈપ કરો ./while (dot slash while) .Enter દબાવો


02.52 આઉટપુટ દ્રશ્યમાન થાય છે.
02.54 હવે ચાલો while loopની કામગીરી જોઈએ.
02.57 ચાલો હું વિન્ડોનું માપ બદલું.
03.00 અહી , પહેલા x અને y ની વેલ્યુ 0 છે.


03.04 આ આપણી while કન્ડીશન છે.
03.06

અહી આપણે તપાસ કરીએ છીએ કે x10 જેટલી અથવા એ કરતા ઓછી કે નહી એટલે કે x ની વેલ્યુ 0 થી 10સુધી રહેશે.


03.15 ત્યારબાદ આપણે y plus x ઉમેરીએ છીએ એટલેકે 0 plus 0 આપણે 0 મળે છે .
03.22 આપણે y ની વેલ્યુ પ્રિન્ટ કરીએ છીએ અહી આપણને 0મળે છે.
03.27 હવે x ને વધારવા માં આવે છે જેનો અર્થ એ છે કે હવે x ની વેલ્યુ 1 રહેશે.
03.33 Then we will check the condition again, 1 is less than or equal to 10, if the condition is true then we will add the values,
03.44 y (i.e ) 0 plus x that is 1. 0 plus 1 is 1
03.50 We print the value as 1.
03.53 Again x is incremented.
03.55 Now the value of x is 2.
03.59 We check the condition again.
04.01 2 is less than or equal to 10, if the condition is true then we will add the values, (i.e ) 1 plus 2 which will give 3.
04.11 We print the value as 3.
04.13 Like this it will go on upto x is less than or equal to 10
04.20 Now, we will see the same program using do….while loop
04.24 Here is our program
04.26 Note that our file name is do hyphen while dot c
04.31 This part is already explained in the previous program.
04.35 So lets us move on to a do...while loop
04.38 Here first the body of the loop will be executed and then the condition is checked.
04.44 The value of x is added to the value of y and the value obtained after the addition is stored in y
04.52 The logic is same as in while program
04.55 Now lets us execute the program
04.58 Come back to our terminal
05.00 Type gcc space do hyphen while dot c space hyphen o space do . Press Enter
05.08 Type dot slash do . Press Enter
05.12 We can see that the output is similar to our while program
05.16 Now, lets us see the working of do...while loop
05.20 Let me resize the window
05.22 Here the value x and y is 0
05.25 We add those values then we will get 0
05.29 Now the value of y is 0.
05.31 We print the value as 0
05.33 Then x is incremented by 1 which means now the value of x is 1, then the condition will be checked.
05.42 You can see that the body of loop is executed first.
05.45 Anyhow if the condition is false then also we will get a value that is 0.
05.52 Now, here we will check whether 1 is less than or equal to 10


05.56 The condition is true again we will add the values.
06.00 Now 0 plus 1.
06.02 Then we will print the value of y as 1


06.05 Again x will be incremented.
06.08 Now the value of x is 2.
06.11 Then we check 2 is less than or equal to 10
06.15 We will go back here
06.17 Then we will add the values 1 plus 2 is 3
06.20 We print the value of y as 3
06.23 Like this the conditions will be checked till the value of x will be less than or equal to 10
06.30 And this is our return statement.
06.33 Note that here the while condition ends with the semicolon
06.38 In while loop the condition does not end with the semicolon.
06.43 Now lets us see how to execute these programs in C++
06.48 This is our while program in C++
06.52 The logic and implementation are same as in our C program
06.56 There are a few changes like the header file as iostream in place of stdio.h


07.04 We have included the using statement here using namespace std and here we have use the cout function in place of printf function
07.16 The structure of while loop is same as in our C program.
07.21 Lets us execute the program
07.23 Come back to a terminal
07.25 Let me clear the prompt


07.28 To execute type g++ space while dot cpp space hyphen o space while1 . Press Enter
07.38 Type dot slash while1 .Press Enter
07.43 You can see that the output is similar to our while program in C.
07.48 Now let us see the do... while program in C++
07.52 Come back to the Text editor
07.54 Here also there are similar changes like the header file ,the using statement and the cout function
08.03 Rest of the things are similar
08.06 Lets us execute the program.
08.08 Come back to our terminal
08.10 Type g++ space do hyphen while dot cpp space hyphen o space do1 . Press Enter
08.19 Type dot slash do1 .Press Enter
08.23 We can see that the output is similar to our do...while program in C.
08.28 Now we will see some common errors and their solutions
08.32 Come back to our text editor
08.35 Suppose here I will not increment the value of x.
08.41 Click on Save.
08.42 Let us see what happens
08.44 Come back to the terminal.
08.45 Let me clear the prompt
08.47 Lets us execute the program.
08.50 Press the uparrow key twice.
08.54 Again press the uparrow key


08.57 The output is displayed.
08.59 We can see number of zeros, this is because the loop does not have the terminating condition .
09.07 It is known as infinite loop.


09.10 Infinite loop can cause the system to become unresponsive.
09.14 It causes the program to consume all the processors time but it can be terminated
09.21 Come back to our program, let us fix the error.
09.25 Type x++ and a semicolon.
09.28 Click on Save. Let us execute again.
09.31 Come back to terminal.
09.33 Press the uparrow key
09.38 Yes, it is working
09.40 This bring us to the end of this tutorial.
09.43 We will move back to our slides.
09.45 Let us summarize


09.47 In this tutorial we learned,
09.50 while loop
09.51 example. while(x is less than or equal to 10)
09.54 do….while loop
09.56 example. do statement block and


09.59 while condition at the end
10.01 As an assignment
10.03 Write a program to print the following using for loops
10.07 0 to 9
10.10 The syntax of the for loop is
10.12 for (variable initialization; variable condition;and variable increment or decrement)
10.20 And here will be the body of the loop
10.24 Watch the video available at the link shown below
10.27 It summarizes the Spoken Tutorial project
10.30 If you do not have good bandwidth, you can download and watch it
10.33 The Spoken Tutorial Project Team
10.35 Conducts workshops using spoken tutorials
10.38 Gives certificates to those who pass an online test
10.42 For more details, please write to, contact@spoken-tutorial.org
10.47 Spoken Tutorial Project is a part of Talk to a Teacher project
10.51 It is supported by the National Mission on Education through ICT, MHRD, Government of India
10.58 More information on this Mission is available at the link shown below
11.02 This script as been contributed by Dhawal Goyal. This is Ashwini Patil from IIT Bombay signing off
11.08 Thank You for joining.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya, Pratik kamble