Causes the remaining portion of the enclosing for, range-for, while or do-while loop body to be skipped.
Used when it is otherwise awkward to ignore the remaining portion of the loop using conditional statements.
attr (optional) continue ; |
The continue
statement causes a jump, as if by goto to the end of the loop body (it may only appear within the loop body of for, range-for, while, and do-while loops).
More precisely,
For while loop, it acts as.
For do-while loop, it acts as:
For for and range-for loop, it acts as:
#include <iostream> int main() { for (int i = 0; i < 10; i++) { if (i != 5) continue; std::cout << i << " "; // this statement is skipped each time i != 5 } std::cout << '\n'; for (int j = 0; 2 != j; ++j) { for (int k = 0; k < 5; k++) // only this loop is affected by continue { if (k == 3) continue; // this statement is skipped each time k == 3: std::cout << '(' << j << ',' << k << ") "; } } }
Output:
C documentation for continue |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/language/continue