I've got a piece of code that successfully runs a loop 80 times. Here's the code snippet:
```c
for (int i = 0; i < 80; ++i) {
// some logic here
}
```
But I want to modify it so that it skips the number '19'. Does anyone know the best way to implement this?
3 Answers
Just to clarify, using `++i` versus `i++` in this case doesn't affect your loop output. Both will give you a loop from 0 to 79, but the increment method does change when the value is applied in calculations. So, in this case, it's all good!
Another way to handle this is by using an `if-else` structure. Check if `i` is '19' to avoid executing your logic. Just use `if (i != 19) { /* logic */ } else { /* blank or other action */ }`. But honestly, the `continue` approach is way cleaner!
Yeah, I totally agree. The `continue` makes it much easier to read!
You can easily skip the number '19' by adding a simple `if` statement inside your loop. Just use `if(i == 19) continue;` to jump to the next iteration whenever it hits '19'. Here's how it looks:
```c
for (int i = 0; i < 80; ++i) {
if(i == 19) continue;
// your logic here
}
```
Right? I thought the same thing initially, but they both work fine here.