Java/C2/do-while/Gujarati
From Script | Spoken-Tutorial
| Time' | Narration |
| 00:01 | જાવામાં do -while લૂપ પરના સ્પોકન ટ્યુટોરીયલમાં તમારું સ્વાગત છે. |
| 00:06 | આ ટ્યુટોરીયલમાં આપણે શીખીશું,
|
| 00:12 | આ ટ્યુટોરીયલ માટે આપણે
Ubuntu 11.10, JDK 1.6 અને Eclipse 3.7 નો ઉપયોગ કરી રહ્યા છીએ. |
| 00:20 | આ ટ્યુટોરીયલ અનુસરવા માટે, તમને જાવામાં while લુપ વિષે જ્ઞાન હોવું જરૂરી છે |
| 00:25 | જો નહિં, તો સંબંધિત ટ્યુટોરિયલ્સ માટે અમારી વેબસાઇટ http://spoken-tutorial.org/ જુઓ. |
| 00:32 | અહીં do while લૂપનું સ્ટ્રક્ચર છે. |
| 00:37 | નોંધ લો કે તે while લૂપ જેવું જ છે. |
| 00:40 | તેના બે ભાગો છે. |
| 00:42 | પ્રથમ લુપ રનીંગ કન્ડીશન છે અને બીજું લુપ વેરિયેબલ છે. |
| 00:51 | માત્ર એક ફરક છે કે કન્ડીશન do બ્લોક પછી આવે છે. |
| 00:58 | અને તેથી કન્ડીશન do બ્લોક અંદર આવેલા સ્ટેટમેન્ટ એક્ઝીક્યુટ થયા પછી ચેક થશે. |
| 01:05 | ચાલો ઉદાહરણ જોઈએ. |
| 01:07 | eclipse ઉપર જાઓ. |
| 01:11 | અહીં આપણી પાસે eclipse IDE અને બાકીના કોડ માટે જરૂરી માળખું છે. |
| 01:17 | આપણે DoWhileDemo નામનો એક ક્લાસ બનાવેલ છે અને તે અંદર મેઈન મેથડ ઉમેર્યી છે. |
| 01:22 | આપણે do -while લૂપની મદદથી 1 થી 10 નંબરો પ્રિન્ટ કરીશું. |
| 01:27 | ટાઇપ કરો, |
| 01:29 | int n ઇકવલ ટુ 1
|
| 01:32 | વેરિયેબલ n આપણું લૂપ વેરિયેબલ બનશે. |
| 01:36 | પછી ટાઇપ કરો, do |
| 01:40 | ઓપન અને ક્લોસ કૌંસ |
| 01:44 | કૌંસ અંદર System.out.println(n); |
| 01:55 | આપણે n ની વેલ્યુ પ્રિન્ટ કરીશું અને પછી તેને ઇન્ક્રીમેન્ટ કરીશું. n ઇકવલ ટુ n plus 1; |
| 02:05 | અને આપણે આ, |
| 02:08 | n લેસ ધેન ઓર ઇકવલ ટુ 10 ન થાય ત્યાં સુધી કરીશું. |
| 02:10 | કૌંસ બહાર, ટાઇપ કરો, while કૌંસ અંદર, (n લેસ ધેન ઓર ઇકવલ ટુ 10) |
| 02:20 | અને સેમીકોલનનો ઉપયોગ કરી do -while બંધ કરો. |
| 02:25 | ચાલો કોડને એક્શનમાં જોઈએ. |
| 02:28 | સેવ અને રન કરો. |
| 02:37 | આપણે જોઈ શકીએ છીએ, 1 થી 10 નંબરો પ્રિન્ટ કરવામાં આવેલ છે. |
| 02:42 | હવે ચાલો સમજીએ કે આ કોડ કેવી રીતે એક્ઝીક્યુટ થાય છે. |
| 02:47 | પ્રથમ 1 પ્રિન્ટ થાય છે અને પછી n ની વેલ્યુ 2 બને છે. |
| 02:52 | પછી કન્ડીશન ચેક થશે. |
| 02:55 | તે true છે તેથી ફરીથી 2 પ્રિન્ટ થયેલ છે અને n 3 બને છે. |
| 03:00 | અને એ રીતે 10 પ્રિન્ટ થાય ત્યાં સુધી લુપ વધે છે, તે પછી n ની વેલ્યુ 11 બને છે |
| 03:06 | જયારે n = 11 થાય છે, કન્ડીશન નિષ્ફળ જાય છે અને લૂપ અટકે છે. |
| 03:11 | હવે ચાલો 50 થી 40' નંબરો ઉતરતા ક્રમમાં પ્રિન્ટ કરીએ. |
| 03:17 | તો આપણે 50 થી શરૂ કરીશું. |
| 03:19 | n = 1 ને n = 50 થી બદલો. |
| 03:23 | આપણે મોટા નંબરથી નાના નંબર માટે લુપીંગ કરી રહ્યા છે, તેથી આપણે લુપ વેરિયેબલ ડીક્રીમેન્ટ કર્યો છે. |
| 03:29 | તો n=n + 1 ને n=n - 1 થી બદલો. |
| 03:34 | આપણે n ગ્રેટર ધેન ઓર ઇકવલ ટુ 40 થાય ત્યાં સુધી લુપ કરીશું. |
| 03:40 | તેથી કન્ડીશન n >= 40 થી બદલો. |
| 03:48 | ચાલો આઉટપુટ જોઈએ. |
| 03:50 | સેવ અને રન કરો. |
| 03:57 | આપણે જોઈ શકીએ છીએ, 50 થી 40 નંબરો પ્રિન્ટ થયા છે. |
| 04:02 | હવે do-while લુપની મદદથી વિવિધ લોજીકનો પ્રયાસ કરીએ. |
| 04:10 | આપેલ નંબર સંપૂર્ણ વર્ગ છે કે નહી તે શોધો. |
| 04:15 | પ્રથમ મેઈન મેથડ ક્લીયર કરો. |
| 04:19 | પછી ટાઇપ કરો, int n = 25; |
| 04:25 | n ની વેલ્યુ સંપૂર્ણ વર્ગ છે કે નહી તે જોઈશું. |
| 04:32 | પછી ટાઇપ કરો, int x = 0; |
| 04:37 | આપણે, જો નંબર સંપૂર્ણ વર્ગ હોય તો તેનું વર્ગમૂળ સંગ્રહવા માટે x નો ઉપયોગ કરીશું. |
| 04:44 | પછી ટાઇપ કરો, do |
| 04:46 | ઓપન અને ક્લોસ કૌંસ. |
| 04:49 | કૌંસ અંદર, x ઇકવલ ટુ x પ્લ સ 1 |
| 04:55 | અને કૌંસ બહાર, |
| 04:58 | while કૌંસ અંદર (x ઇન ટુ x < n) |
| 05:06 | અને સેમી કોલન નો ઉપયોગ કરી do-while બંધ કરો. |
| 05:10 | જ્યાં સુધી x ઇન ટુ x લેસ ધેન n હશે, ત્યાં સુધી આપણે x ની વેલ્યુ ઇન્ક્રીમેન્ટ કરીશું. |
| 05:16 | તો જયારે લૂપ અટકે છે, આ કન્ડીશનનું વિપરીત true થશે. |
| 05:22 | Which means either x into x must be equal to n.
|
| 05:26 | Or it must be greater than n. |
| 05:28 | If x into x is equal to n, the number is a perfect square.
|
| 05:32 | If it is not equal to n, the number is not a perfect square. |
| 05:37 | So finally, we print the condition. |
| 05:47 | System.out.println(x * x == n); |
| 05:55 | Let us see the code in action. |
| 05:59 | Save and Run. As we can see, the output is true
|
| 06:07 | Let us try with other perfect square. |
| 06:10 | Change n = 25 to n = 49 |
| 06:15 | Save and Run |
| 06:20 | We see that we get the true again . |
| 06:23 | Let us try with a number which is not a perfect square. |
| 06:26 | Change 49 to 23. Save and Run and
|
| 06:34 | We get a false as expected.
|
| 06:37 | Now let us see what happens when the value of n is 0. |
| 06:42 | Change n = 23 to n = 0 Since 0 is not a natural number, we must get a false.
|
| 06:52 | Let us run the code. |
| 06:54 | Save and Run. |
| 07:00 | We see that we get false as expected. |
| 07:05 | This happens because even before the condition |
| 07:08 | x into x is less than n is checked, the value of x is incremented and it becomes 1
|
| 07:16 | The loop condition fails and loop does not run. |
| 07:20 | This way, by using a do-while loop, we make sure that 0 is not considered as a perfect square. |
| 07:26 | This way, a do-while loop is used for solving a range of problems. |
| 07:31 | Specially, when the loop must run at least once. |
| 07:37 | This brings us to the end of the tutorial.
|
| 07:40 | In this tutorial, we learnt about the |
| 07:42 | The do-while loop and how to use it |
| 07:46 | As an assignment for this tutorial, solve the following problem.
|
| 07:50 | Given a binary number, find out its decimal equivalent. Example: 11010 => 26 |
| 07:56 | To know more about the Spoken Tutorial project, watch the video available at the following link. |
| 08:01 | It summarizes the spoken-tutorial project.If you do not have good bandwidth, you can download and watch it. |
| 08:06 | The Spoken Tutorial Project Team. |
| 08:10 | Conducts workshops using spoken tutorials .gives certificates for those who pass an online test. |
| 08:16 | For more details, please write to contact AT spoken HYPHEN tutorial DOT org. |
| 08:22 | The Spoken Tutorial Project is a part of the Talk to a Teacher project . It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
| 08:32 | More information on this Mission is available at the following link |
| 08:36 | This tutorial has been contributed by TalentSprint. Thanks for joining.
|