Loop continue problems

how is this code not outputing anything?
since, i=-1 will eventually become higher than 5, it should be saying "Hello" multiple times. why is that so?
what is the continue statement doing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  #include <iostream>

using namespace std;


int main() {
    for(int i=-1; i<=10; i++)
    {if (i <5 ) continue;
    else
        break;
    cout <<"Hello";
    }
	return 0;
}
What do you think happens when i == 5?
continue might seem somewhat misleading.
If i is less than five, then restart the loop. Otherwise, break out of the loop.
So, not only are you breaking out of the loop on the first iteration (because the initial value of i is less than five), but even if the loop ever got to a point where i is not less than five, you restart the loop.
Last edited on
Topic archived. No new replies allowed.