Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C++ continue Statement

C++ continue Statement

C++ Loops C++ Loops

The continue continue statement in C++ is somewhat like the break break statement. But instead of forcing termination, continue skips the code in the current loop iteration and forces the next iteration to begin.

For for a for loop, thecontinue continue statement causes the condition test and loop increment parts to execute. For a while and do...while a for loop, thecontinue while statement, it causes program control to return to the condition test.

Syntax

The syntax of the **continue** statement in C++:


continue;

Flowchart

C++ continue Statement

Example

Example

#include

using

namespace

std

;

 

int

main

(

)

{

   

// local variable declaration

   

int

a

=

10

;

   

// do loop execution

   

do

   

{

       

if

(

a

==

15

)

       

{

         

// Skip iteration

          a

=

a

1

;

         

continue

;

       

}

       

cout

<<

"Value of a: "

<<

a

<<

endl

;

       a

=

a

1

;

   

}

while

(

a

<
20
)

;

 

   

return

0

;

}

When the code above is compiled and executed, it produces the following result:


a 的值: 10
a 的值: 11
a 的值: 12
a 的值: 13
a 的值: 14
a 的值: 16
a 的值: 17
a 的值: 18
a 的值: 19

C++ Loops C++ Loops