Java Jump Statements (break, continue, return) – Explained with Examples जावा जंप स्टेटमेंट्स – उदाहरणों के साथ
जावा में जंप स्टेटमेंट्स का उपयोग प्रोग्राम में कंट्रोल फ्लो को नियंत्रित करने के लिए किया जाता है। ये स्टेटमेंट्स लूप्स और मेथड्स में विशिष्ट शर्तों के आधार पर बाहर निकलने, स्किप करने या वैल्यू रिटर्न करने में सहायक होते हैं, जिससे प्रोग्राम अधिक लचीला और प्रभावशाली बनता है।
🛑 break Statement
The break
statement is used to exit a loop or switch-case block prematurely. It is commonly used when a certain condition is met and further execution inside the loop or switch is unnecessary.
break
स्टेटमेंट का उपयोग किसी लूप या switch-case ब्लॉक से अचानक बाहर निकलने के लिए किया जाता है। इसका प्रयोग तब किया जाता है जब किसी शर्त की पूर्ति हो जाती है और लूप या स्विच के अंदर की आगे की प्रक्रिया को रोकना होता है।
Example:
public class BreakExample {
public static void main(String[] args) {for (int i = 1; i <= 10; i++) {if (i == 5) {break;}System.out.println("Value: " + i);}}}
🔁 continue Statement
The continue
statement skips the current iteration of the loop and proceeds with the next iteration. It is useful when you want to skip only certain values or conditions within a loop.
continue
स्टेटमेंट वर्तमान iteration को स्किप करके सीधे अगले iteration पर चला जाता है। इसका प्रयोग तब किया जाता है जब हमें लूप के अंदर कुछ विशेष मानों या स्थितियों को छोड़ना हो।
Example:
public class ContinueExample {
public static void main(String[] args) {for (int i = 1; i <= 5; i++) {if (i == 3) {continue;}System.out.println("Number: " + i);}}}
↩️ return Statement
The return
statement is used to exit from a method and optionally return a value. It plays an important role in function-based programming by sending the result of a method back to the caller.
return
स्टेटमेंट का उपयोग किसी method से बाहर निकलने और यदि आवश्यक हो तो एक वैल्यू को वापस लौटाने के लिए किया जाता है। यह फंक्शन-बेस्ड प्रोग्रामिंग में एक महत्वपूर्ण भूमिका निभाता है।
Example:
public class ReturnExample {
public static int square(int number) {return number * number;}public static void main(String[] args) {int result = square(6);System.out.println("Square is: " + result);}}
📌 Summary
-
break
is used to stop loops or switch-cases. -
continue
skips current iteration of the loop. -
return
exits the method and may return a value. -
break
का प्रयोग लूप या स्विच को रोकने के लिए किया जाता है। -
continue
लूप के वर्तमान iteration को छोड़ देता है। -
return
method को समाप्त करता है और वैल्यू भी वापस कर सकता है।
Comments
Post a Comment