Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I am interested to try it on the platforms:
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si vous n'avez toujours pas reçu de réponse, vérifiez votre dossier
Spam/Junk et cliquez sur le bouton "Not Spam".
De cette façon, vous ne manquerez la réponse de notre équipe.

>
>
>
V696. The 'continue' operator will term…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu Contents

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

24 Jul 2014

The analyzer has detected code that may mislead the programmer. Not every programmer is aware that the continue operator in the "do { ... } while(0)" loop will terminate the loop instead of continuing it.

This is what the standard has to say 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 will be checked and the loop will terminate because the condition is false.

For example:

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

The programmer would expect the program to print "12A", but it will actually print "1".

Even if the code was written that way consciously, you'd better change it. For example, you may 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. You can see right away that the loop will terminate if the (i < 3) condition is true. Besides, the analyzer won't generate the warning on this code.

If the code is incorrect, it needs to be rewritten. I cannot give any precise recommendations about that; it all depends on the code execution logic. For instance, if you want to get "12A" printed, you'd better 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.