saving . . . saved For Loop Behavior Different from Tutorial Example has been deleted. For Loop Behavior Different from Tutorial Example has been hidden .
For Loop Behavior Different from Tutorial Example
Title
Question

I am currently learning C++ through the Spoken Tutorial series, and I came across a confusing behavior in the for loop example from the tutorial.

In my practice, I am also using Pass4Future CPP Practice Questions to improve my understanding of the concepts. While working on one of these questions, I noticed that my for loop behaves differently than what was shown in the tutorial video.

Here is a simplified version of my code:

#include <iostream>

using namespace std;

int main() {

    for (int i = 0; i < 5; i++) {

        cout << i << " ";

    }

    return 0;

}

What I expected: 0 1 2 3 4 but results are differents

I tried to compare it with the tutorial example, but I am still confused about why the behavior is different.

Could someone please help me understand why this is happening? Is this difference related to compiler settings, or my code?


C-and-Cpp Loops 07-08 min 30-40 sec 01-01-26, 5:49 p.m. tonybonde

Answers:

Log-in to answer to this question.