continue
statement
| General topics | ||||||||||||||||
| Flow control | ||||||||||||||||
| Conditional execution statements | ||||||||||||||||
| Iteration statements (loops) | ||||||||||||||||
|
||||||||||||||||
| Jump statements | ||||||||||||||||
|
||||||||||||||||
| Functions | ||||||||||||||||
| Function declaration | ||||||||||||||||
| Lambda function expression | ||||||||||||||||
inline
specifier
|
||||||||||||||||
| Dynamic exception specifications ( until C++17* ) | ||||||||||||||||
noexcept
specifier
(C++11)
|
||||||||||||||||
| Exceptions | ||||||||||||||||
| Namespaces | ||||||||||||||||
| Types | ||||||||||||||||
| Specifiers | ||||||||||||||||
|
||||||||||||||||
| Storage duration specifiers | ||||||||||||||||
| Initialization | ||||||||||||||||
| Expressions | ||||||||||||||||
| Alternative representations | ||||||||||||||||
| Literals | ||||||||||||||||
| Boolean - Integer - Floating-point | ||||||||||||||||
| Character - String - nullptr (C++11) | ||||||||||||||||
| User-defined (C++11) | ||||||||||||||||
| Utilities | ||||||||||||||||
| Attributes (C++11) | ||||||||||||||||
| Types | ||||||||||||||||
typedef
declaration
|
||||||||||||||||
| Type alias declaration (C++11) | ||||||||||||||||
| Casts | ||||||||||||||||
| Memory allocation | ||||||||||||||||
| Classes | ||||||||||||||||
| Class-specific function properties | ||||||||||||||||
|
||||||||||||||||
| Special member functions | ||||||||||||||||
|
||||||||||||||||
| Templates | ||||||||||||||||
| Miscellaneous | ||||||||||||||||
Provoque l'ignorance de la partie restante du corps de la boucle for , range-for , while ou do-while englobante.
Utilisé lorsqu'il est autrement maladroit d'ignorer la portion restante de la boucle en utilisant des instructions conditionnelles.
Table des matières |
Syntaxe
attr
(facultatif)
continue
;
|
|||||||||
Explication
L'instruction
continue
provoque un saut, comme par
goto
vers la fin du corps de la boucle (elle ne peut apparaître que dans le corps de boucle des instructions
for
,
range-for
,
while
, et
do-while
).
Plus précisément,
Pour la boucle while , elle agit comme
while (/* ... */) { // ... continue; // agit comme un goto contin; // ... contin:; }
Pour la boucle do-while , elle agit comme :
do { // ... continue; // agit comme un goto contin; // ... contin:; } while (/* ... */);
Pour la boucle for et la boucle range-for , elle agit comme :
for (/* ... */) { // ... continue; // agit comme goto contin; // ... contin:; }
Mots-clés
Exemple
#include <iostream> int main() { for (int i = 0; i < 10; ++i) { if (i != 5) continue; std::cout << i << ' '; // cette instruction est ignorée chaque fois que i != 5 } std::cout << '\n'; for (int j = 0; 2 != j; ++j) for (int k = 0; k < 5; ++k) // seule cette boucle est affectée par continue { if (k == 3) continue; // cette instruction est ignorée chaque fois que k == 3 : std::cout << '(' << j << ',' << k << ") "; } std::cout << '\n'; }
Sortie :
5 (0,0) (0,1) (0,2) (0,4) (1,0) (1,1) (1,2) (1,4)
Voir aussi
|
Documentation C
pour
continue
|