{"id":2295,"date":"2024-05-10T07:19:39","date_gmt":"2024-05-10T07:19:39","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=2295"},"modified":"2024-05-10T07:19:39","modified_gmt":"2024-05-10T07:19:39","slug":"continue-statement-in-c","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/continue-statement-in-c\/","title":{"rendered":"Continue Statement In C"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#continue-statement-in-c\">Continue Statement In C<\/a><\/li><li ><a href=\"#what-is-continue-in-c\">What is continue in C?<\/a><\/li><li ><a href=\"#syntax-of-continue-in-c\">Syntax of continue in C<\/a><\/li><li ><a href=\"#use-of-continue-in-c\">Use of continue in C<\/a><\/li><li ><a href=\"#example-of-continue-in-c\">Example of continue in C<\/a><\/li><li ><a href=\"#faq-continue-statement-in-c\">FAQ- Continue Statement in C<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"continue-statement-in-c\">Continue Statement In C<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>continue<\/code> statement is indeed a control flow statement used to alter the flow of program execution within loops (such as <code>while<\/code>, <code>for<\/code>, or <code>do...while<\/code>) by skipping the rest of the current iteration and moving to the next iteration of the loop. It is useful when you want to bypass certain code in a loop iteration but continue with the next iteration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-continue-in-c\">What is continue in C?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>continue<\/code> statement, when encountered within a loop, indeed resets program control to the beginning of the loop, effectively skipping the remaining statements within the current iteration. It allows the loop to continue with the next iteration, which can be useful for selectively bypassing certain code within the loop while continuing to execute others. Your explanation clearly conveys the behavior and purpose of the <code>continue<\/code> statement in C.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"syntax-of-continue-in-c\">Syntax of continue in C<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The syntax of continue is just the continue keyword placed wherever we want in the loop body.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>continue;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"use-of-continue-in-c\">Use of continue in C<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The continue statement in C can be used in any kind of loop to skip the current iteration. In C, we can use it in the following types of loops:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Single Loops\nNested Loops<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-continue-in-c\">Example of continue in C<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example 1: C Program to use continue statement in a single loop<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/\/ C program to explain the use\n\/\/ of continue statement with for loop\n \n#include &lt;stdio.h&gt;\n \nint main()\n{\n    \/\/ for loop to print 1 to 8\n    for (int i = 1; i &lt;= 8; i++) {\n        \/\/ when i = 4, the iteration will be skipped and for\n        \/\/ will not be printed\n        if (i == 4) {\n            continue;\n        }\n        printf(\"%d \", i);\n    }\n    printf(\"\\n\");\n \n    int i = 0;\n    \/\/ while loop to print 1 to 8\n    while (i &lt; 8) {\n        \/\/ when i = 4, the iteration will be skipped and for\n        \/\/ will not be printed\n        i++;\n        if (i == 4) {\n            continue;\n        }\n        printf(\"%d \", i);\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1 2 3 5 6 7 8 \n1 2 3 5 6 7 8 <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example 2: C Program to use continue in a nested loop<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ C program to explain the use\n\/\/ of continue statement with nested loops\n#include &lt;stdio.h&gt;\n \nint main()\n{\n \n    \/\/ outer loop with 3 iterations\n    for (int i = 1; i &lt;= 3; i++) {\n        \/\/ inner loop to print integer 1 to 4\n        for (int j = 0; j &lt;= 4; j++) {\n \n            \/\/ continue to skip printing number 3\n            if (j == 3) {\n                continue;\n            }\n            printf(\"%d \", j);\n        }\n        printf(\"\\n\");\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1 2 3 5 6 7 8 \n1 2 3 5 6 7 8 <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example 2: C Program to use continue in a nested loop<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ C program to explain the use\n\/\/ of continue statement with nested loops\n#include &lt;stdio.h&gt;\n \nint main()\n{\n \n    \/\/ outer loop with 3 iterations\n    for (int i = 1; i &lt;= 3; i++) {\n        \/\/ inner loop to print integer 1 to 4\n        for (int j = 0; j &lt;= 4; j++) {\n \n            \/\/ continue to skip printing number 3\n            if (j == 3) {\n                continue;\n            }\n            printf(\"%d \", j);\n        }\n        printf(\"\\n\");\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 1 2 4 \n0 1 2 4 \n0 1 2 4 <\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Example 3: C Program to demonstrate the difference between the working of break and continue statements in C<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ C program to demonstrate difference between\n\/\/ continue and break\n#include &lt;stdio.h&gt;\n \nint main()\n{\n \n    printf(\"The loop with break produces output as: \\n\");\n \n    for (int i = 1; i &lt;= 7; i++) {\n \n        \/\/ Program comes out of loop when\n        \/\/ i becomes multiple of 3.\n        if (i == 3)\n            break;\n        else\n            printf(\"%d \", i);\n    }\n \n    printf(\"\\nThe loop with continue produces output as: \\n\");\n    for (int i = 1; i &lt;= 7; i++) {\n \n        \/\/ The loop prints all values except\n        \/\/ those that are multiple of 3.\n        if (i == 3)\n            continue;\n        printf(\"%d \", i);\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The loop with break produces output as: \n1 2 \nThe loop with continue produces output as: \n1 2 4 5 6 7 <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-continue-statement-in-c\">FAQ- Continue Statement in C<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1696419914775\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is a continue statement?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. A <code>continue<\/code> statement ends the current iteration of a loop.<br \/>Control is passed from the <code>continue<\/code> statement to the end of the loop body.<br \/>The syntax of a <code>continue<\/code> statement is typically <code>continue;<\/code>.<br \/>A <code>continue<\/code> statement can only appear within the body of an iterative statement, such as <code>do<\/code>, <code>for<\/code>, or <code>while<\/code> loops.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1696419919990\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. What is continue in C with example?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. While the <code>break<\/code> statement terminates the loop entirely, the <code>continue<\/code> statement forces the next iteration of the loop to occur, skipping any code that follows it within the current iteration.<br \/>In the case of a <code>for<\/code> loop, the <code>continue<\/code> statement causes the conditional test and increment portions of the loop to execute, effectively moving to the next iteration.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1696419929188\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. What is the break and continue statement in C?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. The <code>break<\/code> statement is used to exit from loop constructs entirely, terminating the loop prematurely.<br \/>In contrast, the <code>continue<\/code> statement is not used to exit from loop constructs but rather to skip the rest of the current iteration and move to the next iteration.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Continue Statement In C The continue statement is indeed a control flow statement used to alter the flow of program execution within loops (such as while, for, or do&#8230;while) by skipping the rest of the current iteration and moving to the next iteration of the loop. It is useful when you want to bypass certain &#8230; <a title=\"Continue Statement In C\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/continue-statement-in-c\/\" aria-label=\"More on Continue Statement In C\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":5345,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[412],"class_list":["post-2295","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-continue-statement-in-c","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=2295"}],"version-history":[{"count":15,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2295\/revisions"}],"predecessor-version":[{"id":10648,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2295\/revisions\/10648"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/5345"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=2295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=2295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=2295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}