{"id":5203,"date":"2021-03-23T12:20:13","date_gmt":"2021-03-23T12:20:13","guid":{"rendered":"https:\/\/ded9.com\/?p=5203"},"modified":"2025-12-10T12:19:28","modified_gmt":"2025-12-10T12:19:28","slug":"continue-command-in-java-in-quite-simple-language","status":"publish","type":"post","link":"https:\/\/ded9.com\/tr\/continue-command-in-java-in-quite-simple-language\/","title":{"rendered":"Understanding the continue Command in Java \u2014 Explained Simply"},"content":{"rendered":"<p><span style=\"font-size: 12pt;\">This tutorial teaches you to use the continue <a href=\"https:\/\/ded9.com\/how-to-clear-command-history-in-linux\/\">Command<\/a> in Java. The continue statement causes the current iteration to continue.<\/span><span id=\"more-50097\"><\/span><\/p>\n<p>Suppose you are working with circles. Sometimes, you want to skip some commands inside or end the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Loop\" target=\"_blank\" rel=\"noopener\">loop<\/a> immediately without checking the condition.<\/p>\n<p>In such cases, the terms break and continue are used. The continue statement skips the remainder of the current iteration of a loop (for, while, or do\u2026 while).<\/p>\n<p>When the continue Command is executed, the program control jumps to the end of the loop. The condition that controls the loop is then evaluated. In the case of a for loop, the variable update statement executes before the condition is evaluated.<\/p>\n<p>Most often used with decision structures (if\u2026 else). The syntax of the continue Command is as follows:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">continue;<\/pre>\n<\/div>\n<h2><span style=\"font-size: 18pt;\">How does the continue statement work?<\/span><\/h2>\n<p><strong><img fetchpriority=\"high\" decoding=\"async\" class=\"lazyloaded aligncenter wp-image-50098\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2025\/02\/c-users-mr-desktop-how-continue-statement-works_0.jpeg\" alt=\"How does the continue statement work?\" width=\"500\" height=\"339\" data-ll-status=\"loaded\" \/><\/strong><\/p>\n<p>Example 1: Continue Command in Java<\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">class Test {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">for (int i = 1; i &lt;= 10; ++ i) {<\/li>\n<li dir=\"ltr\">if (i&gt; 4 &amp;&amp; i &lt;9) {<\/li>\n<li dir=\"ltr\">continue;<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">System.out.println (i);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p>When its value is greater than four and less than nine, the continue statement is executed, preventing i (System.out.println) from being executed.<\/p>\n<p>When running the program, the output will be equal to:<\/p>\n<blockquote>\n<p dir=\"ltr\">1<\/p>\n<p dir=\"ltr\">2<\/p>\n<p dir=\"ltr\">3<\/p>\n<p dir=\"ltr\">4<\/p>\n<p dir=\"ltr\">9<\/p>\n<p dir=\"ltr\">10<\/p>\n<\/blockquote>\n<p><strong>Example 2: The continue statement in Java<\/strong><\/p>\n<p>The following program calculates the sum of a maximum of 5 positive numbers that the user enters. If the user enters a negative or zero number, it will be skipped.<\/p>\n<p>The Scanner object is used to get input from the user.<\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">import java.util.Scanner;<\/li>\n<li dir=\"ltr\">class AssignmentOperator {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">Double number, sum = 0.0;<\/li>\n<li dir=\"ltr\">Scanner input = new Scanner (System.in);<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">for (int i = 1; i &lt;6; ++ i) {<\/li>\n<li dir=\"ltr\">System.out.print (&#8220;Enter a number:&#8221;);<\/li>\n<li dir=\"ltr\">number = input.nextDouble ();<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">if (number &lt;= 0.0) {<\/li>\n<li dir=\"ltr\">continue;<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">sum + = number;<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">System.out.println (\u201cSum =\u201d + sum);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output:<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">Enter a number: 2.2<\/p>\n<p dir=\"ltr\">Enter a number: 5.6<\/p>\n<p dir=\"ltr\">Enter a number: 0<\/p>\n<p dir=\"ltr\">Enter a number: -2.4<\/p>\n<p dir=\"ltr\">Enter a number: -3<\/p>\n<p dir=\"ltr\">Sum = 7.8<\/p>\n<\/blockquote>\n<p>If there are nested loops, continue jumps to the beginning of the inner loop.<\/p>\n<p><img decoding=\"async\" class=\"lazyloaded aligncenter wp-image-50099\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2025\/02\/c-users-mr-desktop-nested-while-loop-continue-jpg.jpeg\" alt=\"If there are nested loops, continue jumps to the beginning of the inner loop.\" width=\"400\" height=\"264\" data-ll-status=\"loaded\" \/><\/p>\n<h3><span style=\"font-size: 14pt;\">Continue Command Tagged<\/span><\/h3>\n<p>The continue command we&#8217;ve discussed so far is unlabeled, which prevents the execution of the remaining commands of the innermost loops for, while, and do\u2026 while.<\/p>\n<p>Another form of the continue Command is the tagged form, which can skip executing commands inside the outer loop.<\/p>\n<h2><span style=\"font-size: 18pt;\">How does the continue tagged Command work?<\/span><\/h2>\n<p><strong><img decoding=\"async\" class=\"lazyloaded aligncenter wp-image-50100\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2025\/02\/c-users-mr-desktop-labeled-java-continue_0-jpg.jpeg\" alt=\"How does the continue tagged Command work?\" width=\"380\" height=\"270\" data-ll-status=\"loaded\" \/><\/strong><\/p>\n<p>Here is the label ID.<\/p>\n<p><strong>Example 3: continue label tagged<\/strong><\/p>\n<blockquote>\n<ol>\n<li dir=\"ltr\">class LabeledContinue {<\/li>\n<li dir=\"ltr\">public static void main (String [] args) {<\/li>\n<li dir=\"ltr\"><\/li>\n<li dir=\"ltr\">label:<\/li>\n<li dir=\"ltr\">for (int i = 1; i &lt;6; ++ i) {<\/li>\n<li dir=\"ltr\">for (int j = 1; j &lt;5; ++ j) {<\/li>\n<li dir=\"ltr\">if (i == 3 || j == 2)<\/li>\n<li dir=\"ltr\">continue label;<\/li>\n<li dir=\"ltr\">System.out.println (\u201ci =\u201d + i + \u201c; j =\u201d + j);<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<li dir=\"ltr\">}<\/li>\n<\/ol>\n<\/blockquote>\n<p><strong>Output<\/strong><\/p>\n<blockquote>\n<p dir=\"ltr\">i = 1;\u00a0j = 1<\/p>\n<p dir=\"ltr\">i = 2;\u00a0j = 1<\/p>\n<p dir=\"ltr\">i = 4;\u00a0j = 1<\/p>\n<p dir=\"ltr\">i = 5;\u00a0j = 1<\/p>\n<\/blockquote>\n<p>Usually, continue to use labeled continue because it makes the code difficult to understand. If you have to use continue tagging, refine your code and try to write it differently to make it more readable.<\/p>\n<h2>FAQ<\/h2>\n<div id=\"rank-math-rich-snippet-wrapper\"><div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-1\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What does the continue statement do in Java?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>When executed inside a loop, continue skips the remaining statements in the current iteration and immediately proceeds to the next iteration.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-2\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">In which loops can I use continue?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can use continue inside any Java loop: for, while, do-while, or enhanced for-each loops.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-3\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is the difference between continue and break in Java loops?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>continue skips only the current iteration and moves on to the next one, whereas break exits the loop entirely.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial teaches you to use the continue Command in Java. The continue statement causes the current iteration to continue. Suppose you are working with circles. Sometimes, you want to skip some commands inside or end the loop immediately without checking the condition. In such cases, the terms break and continue are used. The continue [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":5204,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11513],"tags":[840],"class_list":["post-5203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-2","tag-java"],"acf":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/5203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/comments?post=5203"}],"version-history":[{"count":4,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/5203\/revisions"}],"predecessor-version":[{"id":266018,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/5203\/revisions\/266018"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/media\/5204"}],"wp:attachment":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/media?parent=5203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/categories?post=5203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/tags?post=5203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}