JavaScript Labeled Statement In Hindi

📔 : Java Script 🔗

JavaScript में labeled statement का use break और continue statement के साथ करते हैं , generally JavaScript में labeled statement का use किसी loop को identify करने के लिए किया जाता है।

JavaScript Labeled Statement Syntax

 label_name : 
   statement

label_name JavaScript में reserved keywords को छोड़कर आप कुछ meaningful name दे सकते हैं।

और statement वो while / for loop है जिसे हम label_name के साथ identify कर रहे हैं।


? Note that JavaScript में PHP या C की तरह goto statement नहीं होता है इसलिए labeled statement को आप सिर्फ break या continue statement के साथ ही use कर सकते हैं।

JavaScript Labeled Statement with continue

File : continue.html

Copy Fullscreen Close Fullscreen Run
<!DOCTYPE html>
<html>
 <head>
    <meta charset="utf-8">
    <title>JavaScript labeled statement with continue</title>
 </head>
 <body>
   <script>
      let x;
      mylabel : 
      for(x=1; x <= 5 ; x++)
      {
        if(x==3)
        {
          continue mylabel;
        } 
        document.write(`${x} <br>`);
      }
    </script>
 </body>
</html>
Output
1
2
4
5

Example में आप देख हैं कि for loop को identify करने के लिए label का नाम mylabel दिया है , उसके बाद loop के अंदर एक particular condition पर continue statement का use किया गया है।


continue statement current loop iteration ( या label के according) को skip कर देता है।

Learn more about continue statement ..

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers