summaryrefslogtreecommitdiff
path: root/devdocs/c/language%2Fcontinue.html
blob: 831fd254217831fbe23400c6ed6751ca845b236a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 &lt;stdio.h&gt;
 
int main(void) 
{
    for (int i = 0; i &lt; 10; i++) {
        if (i != 5) continue;
        printf("%d ", i);             // this statement is skipped each time i != 5
    }
 
    printf("\n");
 
    for (int j = 0; j &lt; 2; j++) {
        for (int k = 0; k &lt; 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">
    &copy; 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>