Java continue Statement In Hindi

📔 : Java 🔗

Java में continue का use किसी दी गयी condition के according while loop , for loop iteration को skip करने के लिए किया जाता है। और skip करने के बाद Loop next iteration से Start हो जाता है। simply हम कह सकते हैं कि Java में Continue का use हम वहाँ करते हैं जब हमें किसी condition पर loop execution को skip करना हो।

Java continue Syntax

continue;

Java continue Example

File : ContinueExample.java

CopyFullscreenClose FullscreenRun
public class ContinueExample {
  public static void main(String[] args) {
    for(int num = 1; num <= 10; num++) {
      // skip iteration when value of num is 3.
      if(num == 3) {
        continue;
      }
      System.out.println(num);
    }
  }
}
Output
javac ContinueExample.java
java ContinueExample
1
2
4
5

Example में आप देख सकते हैं कि num की value 3 होते ही वो level skip होकर next iteration start हो गयी।

? continue statement loop execution को terminate नहीं करता है current iteration को skip करता है, जैसा कि अभी आपने example में देखा।

Important
? well , well , Java में continue statement JavaScript, PHP से थोड़ा अलग होता है क्योंकि PHP और JavaScript में continue statement के साथ argument भी pass कर सकते हैं , जो define करता है कि एक बार में कितने loop skip करने हैं। लेकिन Java में ऐसा नहीं है , यह continue के साथ कोई argument pass नहीं होता है। यह जिस loop में use होगा उसी की iteration को skip करता है।

Java continue with while Loop

ठीक इसी तरह से आप while loop के साथ भी continue statement को use कर सकते हैं।

File : ContinueExample.java

CopyFullscreenClose FullscreenRun
public class ContinueExample {
  public static void main(String[] args) {
    int num = 0;
    while(num < 5) {
      // increase by 1.
      num++;
      // skip iteration when value of num is 3.
      if(num == 3) {
        continue;
      }
      System.out.println(num);
    }
  }
}
Output
javac ContinueExample.java
java ContinueExample
1
2
4
5

Important

  • while loop में continue statement current loop execution skip करके वापस condition पर जाता है।
  • for loop में continue statement current loop execution skip करके वापस updated iteration पर जाता है। 

continue का use किसी loop के अंदर ही कर सकते हैं , normal statements या if else के साथ आप break use नहीं कर सकते हैं।

Error !

if(num == 5) {
   continue;
}

error: continue outside of loop
       continue;
       ^
1 error

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