diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/language%2Fcontinue.html | |
new repository
Diffstat (limited to 'devdocs/c/language%2Fcontinue.html')
| -rw-r--r-- | devdocs/c/language%2Fcontinue.html | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/devdocs/c/language%2Fcontinue.html b/devdocs/c/language%2Fcontinue.html new file mode 100644 index 00000000..831fd254 --- /dev/null +++ b/devdocs/c/language%2Fcontinue.html @@ -0,0 +1,61 @@ + <h1 id="firstHeading" class="firstHeading">continue statement</h1> <p>Causes the remaining portion of the enclosing <a href="for" title="c/language/for">for</a>, <a href="while" title="c/language/while">while</a> or <a href="do" title="c/language/do"> do-while</a> loop body to be skipped.</p> +<p>Used when it is otherwise awkward to ignore the remaining portion of the loop using conditional statements.</p> +<h3 id="Syntax"> Syntax</h3> <table class="t-sdsc-begin"> <tr class="t-sdsc"> <td class="t-sdsc-nopad"> <span class="t-spar">attr-spec-seq</span><span class="t-mark">(optional)</span> <code>continue</code> <code>;</code> </td> <td class="t-sdsc-nopad"> </td> <td class="t-sdsc-nopad"> </td> +</tr> +</table> <table class="t-par-begin"> <tr class="t-par"> <td> <span class="t-spar">attr-spec-seq</span> </td> <td> - </td> <td> <span class="t-mark-rev t-since-c23">(C23)</span>optional list of <a href="attributes" title="c/language/attributes">attributes</a>, applied to the <code>continue</code> statement </td> +</tr> +</table> <h3 id="Explanation"> Explanation</h3> <p>The <code>continue</code> statement causes a jump, as if by <a href="goto" title="c/language/goto">goto</a>, to the end of the loop body (it may only appear within the loop body of <a href="for" title="c/language/for">for</a>, <a href="while" title="c/language/while">while</a>, and <a href="do" title="c/language/do">do-while</a> loops).</p> +<p>For <a href="while" title="c/language/while">while</a> loop, it acts as</p> +<div class="c source-c"><pre data-language="c">while (/* ... */) { + // ... + continue; // acts as goto contin; + // ... + contin:; +}</pre></div> <p>For <a href="do" title="c/language/do">do-while</a> loop, it acts as:</p> +<div class="c source-c"><pre data-language="c">do { + // ... + continue; // acts as goto contin; + // ... + contin:; +} while (/* ... */);</pre></div> <p>For <a href="for" title="c/language/for">for</a> loop, it acts as:</p> +<div class="c source-c"><pre data-language="c">for (/* ... */) { + // ... + continue; // acts as goto contin; + // ... + contin:; +}</pre></div> <h3 id="Keywords"> Keywords</h3> <p><a href="../keyword/continue" title="c/keyword/continue"><code>continue</code></a></p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> + +int main(void) +{ + for (int i = 0; i < 10; i++) { + if (i != 5) continue; + printf("%d ", i); // this statement is skipped each time i != 5 + } + + printf("\n"); + + for (int j = 0; j < 2; j++) { + for (int k = 0; k < 5; k++) { // only this loop is affected by continue + if (k == 3) continue; + printf("%d%d ", j, k); // this statement is skipped each time k == 3 + } + } +}</pre></div> <p>Output:</p> +<div class="text source-text"><pre data-language="c">5 +00 01 02 04 10 11 12 14</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul><li> 6.8.6.2 The continue statement (p: 111) </li></ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 6.8.6.2 The continue statement (p: 153) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 6.8.6.2 The continue statement (p: 138) </li></ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 3.6.6.2 The continue statement </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/language/continue" title="cpp/language/continue">C++ documentation</a></span> for <span class=""><span><code>continue</code> statement</span></span> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/language/continue" class="_attribution-link">https://en.cppreference.com/w/c/language/continue</a> + </p> +</div> |
