5 ms·
The body of the loop will run |INT_MIN| + 1 times. I don't think there is a more well-accepted definition of "iteration" than that.
by user-the-name 6y ago
The body of the loop will run |INT_MIN| + 1 times. I don't think there is a more well-accepted definition of "iteration" than that.
- jonsen 6y ago> ...well-accepted definition of "iteration"... To say or perform again; repeat. synonym: repeat. To utter or do again; repeat: as, to iterate an advice or a demand. Repeated. So x+1 times is x iterations.
- user-the-name 6y agoI don't think I have ever heard a programmer say that running a piece of code two times is "one iteration".
- jonsen 6y agoBut they can say both of: - From 1 to 10 there is 9 - From 1 to 10 there is 10 How far from 0 to INT_MIN - it depends.
- user-the-name 6y agoNone of that affects the fact that if a loop runs 10 times, all programmers will say that it ran for 10 iterations.
- jonsen 6y agoYes. My point here is that Thorrez at the start of this thread may have a point: Start 0 1. iteration -1 2. iteration -2 3. iteration -3 ... at the end of the |INT_MIN|’th iteration INT_MIN
- wruza 6y agoYou may define or argue that it is, but it's not a common sense for anyone.
- jonsen 6y agoAgree regarding programming. But this could be common sense: Start 0 1. iteration -1 2. iteration -2 3. iteration -3 ... at the end of the |INT_MIN|’th iteration INT_MIN
- deleted 6y ago[deleted]
- Thorrez 6y agoWhy are you only including the body of the loop and not the iteration statement? Like I said, cppreference seems to include the iteration statement as part of the iteration.
- user-the-name 6y agoBecause it is the body that people care about when they talk about algorithms. But even if you include it, it is ran exactly as many times as the body of the loop, so not sure why you bring it up?
- Thorrez 6y ago>Because it is the body that people care about when they talk about algorithms. The article isn't just talking about what happens in the body. It's also talking about what the value of i is after an iteration is done. >But even if you include it, it is ran exactly as many times as the body of the loop, so not sure why you bring it up? That's exactly why I bring it up: After 0 iterations, the iteration statement ran 0 times, so i is 0. After 1 iteration, the iteration statement ran 1 time, so i is -1. After 2 iterations, the iteration statement ran 2 times, so i is -2. ... After |INT_MIN| iterations, the iteration statement ran |INT_MIN| times, so i is INT_MIN. This directly contradicts the article. My point is that the article has an error. If on the other hand you say the iteration statement isn't part of the iteration you get: After 0 iterations, the iteration statement ran 0 times, so i is 0. After 1 iteration, the iteration statement ran 0 times, so i is 0. After 2 iterations, the iteration statement ran 1 time, so i is -1. ... After |INT_MIN| + 1 iterations, the iteration statement ran |INT_MIN| times, so i is INT_MIN. I don't agree with that point of view. But it does agree with the article.