⏭️ C++ continue Statement– Skip Loop Iterations
The continue statement tells your loop: “Skip the rest of this round and jump to the next one!” 🕴️
It’s perfect when you want to ignore certain values or skip specific cases during looping.
🧠 Syntax of continue
continue;
Place it inside a loop when you want to skip that specific iteration.
🔧 Example: Skip Even Numbers
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 5; i++) {
if (i % 2 == 0) {
continue; // skip even numbers
}
cout << "i = " << i << endl;
}
return 0;
}
Output:
i = 1 i = 3 i = 5
🎯 When to Use continue?
- To skip unwanted iterations in loops
- When a specific condition means “don’t do anything this time”
- To avoid using nested if-else blocks unnecessarily
The continue statement is like a fast-forward button in your loop—skip the boring part and move on! ⏩