हिन्दी में वैबसाइट डिजाइनिंग सीखना चाहते हैं तो हमारी साइट code sikho hindi को Subscribe करें

JavaScript - While Loops Full Details

 JavaScript - While Loops Full Details

JavaScript - While Loops Full Details


जावास्क्रिप्ट - While Loops पूर्ण विवरण


एक प्रोग्राम लिखते समय, आप एक ऐसी स्थिति का सामना कर सकते हैं जहाँ आपको एक क्रिया को बार-बार करने की आवश्यकता होती है। ऐसी स्थितियों में, आपको लाइनों की संख्या कम करने के लिए लूप स्टेटमेंट लिखने की आवश्यकता होगी।


प्रोग्रामिंग के दबाव को कम करने के लिए जावास्क्रिप्ट सभी आवश्यक लूपों का समर्थन करता है।


The while Loop- (जबकि लूप)


जावास्क्रिप्ट में सबसे बुनियादी लूप जबकि लूप है जिसकी चर्चा इस अध्याय में की जाएगी। थोड़ी देर के लूप का उद्देश्य किसी कथन या कोड ब्लॉक को बार-बार निष्पादित करना है जब तक कि अभिव्यक्ति सत्य है। एक बार अभिव्यक्ति झूठी हो जाने पर, लूप समाप्त हो जाता है।


Flow Chart- (प्रवाह चार्ट)


जबकि लूप का फ्लो चार्ट इस प्रकार दिखता है -

while Loop Flow Chart- (प्रवाह चार्ट)


Syntax- (वाक्य - विन्यास)


जावास्क्रिप्ट में जबकि लूप का सिंटैक्स इस प्रकार है -


while (expression) {

   Statement(s) to be executed if expression is true

}


Example-उदाहरण


लूप के दौरान लागू करने के लिए निम्न उदाहरण आज़माएं।


<html>

   <body>

      <script type = "text/javascript">

         <!--

            var count = 0;

            document.write("Starting Loop ");

         

            while (count < 10) {

               document.write("Current Count : " + count + "<br />");

               count++;

            }        

            document.write("Loop stopped!");

         //-->

      </script>     

      <p>Set the variable to different value and then try...</p>

   </body>

</html>


Output


Starting Loop

Current Count : 0

Current Count : 1

Current Count : 2

Current Count : 3

Current Count : 4

Current Count : 5

Current Count : 6

Current Count : 7

Current Count : 8

Current Count : 9

Loop stopped!

Set the variable to different value and then try... 


The do...while Loop- (डू ... जबकि लूप)


डू ... जबकि लूप लूप के समान है, सिवाय इसके कि स्थिति की जांच लूप के अंत में होती है। इसका मतलब है कि लूप हमेशा कम से कम एक बार निष्पादित किया जाएगा, भले ही स्थिति गलत हो।


Flow Chart- (प्रवाह चार्ट)


डू-जबकि लूप का फ्लो चार्ट इस प्रकार होगा -

The do...while Loop flow chart


Syntax-वाक्य - विन्यास


जावास्क्रिप्ट में डू-वोल लूप का सिंटैक्स इस प्रकार है -


do {

   Statement(s) to be executed;

} while (expression);


नोट - लूप के दौरान do... के अंत में उपयोग किए गए अर्धविराम से न चूकें।


Example-उदाहरण


जावास्क्रिप्ट में डू-टाइम लूप को कार्यान्वित करने का तरीका जानने के लिए निम्न उदाहरण आज़माएं।


<html>

   <body>   

      <script type = "text/javascript">

         <!--

            var count = 0;            

            document.write("Starting Loop" + "<br />");

            do {

               document.write("Current Count : " + count + "<br />");

               count++;

            }           

            while (count < 5);

            document.write ("Loop stopped!");

         //-->

      </script>      

      <p>Set the variable to different value and then try...</p>

   </body>

</html>


Output


Starting Loop

Current Count : 0 

Current Count : 1 

Current Count : 2 

Current Count : 3 

Current Count : 4

Loop Stopped!

Set the variable to different value and then try...