Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V696. The 'continue' operator will...
menu mobile close menu
Additional information
toggle menu Contents

V696. The 'continue' operator will terminate 'do { ... } while (FALSE)' loop because the condition is always false.

Jul 24 2014

The analyzer has detected code that may be misleading The continue operator in the do { ... } while(0) loop terminates the loop instead of continuing it.

This is what the standard says about it:

§6.6.2 in the standard: "The continue statement (...) causes control to pass to the loop-continuation portion of the smallest enclosing iteration-statement, that is, to the end of the loop." (Not to the beginning.)

Thus, after calling the continue operator, the (0) condition is checked, and the loop terminates because the condition is false.

The example:

int i = 1;
do {
    std::cout << i;
    i++;
    if(i < 3) continue;
    std::cout << 'A';
} while(false);

A developer would expect the program to print 12A, but it will actually print 1.

Even if the code was intentionally written this way, it is better to revise it. For example, you can use the break operator:

int i=1;
do {
    std::cout << i;
    i++;
    if(i < 3) break;
    std::cout << 'A';
} while(false);

The code looks clearer now: the loop will terminate if the (i < 3) condition is true. The analyzer will not issue the warning for this code.

If the code is incorrect, it needs to be rewritten. There are no specific recommendations for this—everything depends on the code execution logic. For example, if you want to print 12A, it is better to write the following code:

for (i = 1; i < 3; ++i)
  std::cout << i;
std::cout << 'A';

This diagnostic is classified as:

You can look at examples of errors detected by the V696 diagnostic.

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
close form
Free PVS‑Studio license for Microsoft MVP specialists
close form
To get the licence for your open-source project, please fill out this form
close form
I want to join the test
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam