0
HELP
#include <iostream> using namespace std; int main() { int i=1; while(i<10) { cout << i << endl ; if(i==5) { continue ; } ++i; } return 0; } Output - 1 2 3 4 5 5 5 5 ... WHY THIS IS HAPPENING
5 Answers
+ 2
when continue operator is execute then increment of counter (i++) is never happened. you need to do like that:
...
if(i==5) {
i++; continue; }
i++;
...
+ 1
At i = 5 it will skip that particular iteration and continue to execute another iteration.
Here i is not incremented in if statement therefore i value will be 5 and it will create an infinite loop.
If your code is like this
if(i==5)
{
i++;
continue;
}
Than output will be
1 2 3 4 6 7 8 9
+ 1
Right Indiegma.
first i++ than continue.
0
Thanks everyone
- 2
meet mehta.
if(i==5){
continue;
i++;}
your code will not work correctly, because i++ will be skipped always



