I am quite new to c++, and I believe the answer to my problem is very, very simple.
I've been using the Eclipse IDE, but have recently changed to a simple text editor and using the command line for compiling. (As i currently don't have my own computer, and I am not allowed to install anything on the one I am using).
However, while writing a program, I noticed that whenever I had nested loops, it would only run the inner loop.
I've tried compiling my code using different online compilers, which results in the same problem.
Because of this, I believe that the problem is related to something simple, that Eclipse was taking care of automatically.
#include <iostream>
int main() {
for (int i; i<3; i++) {
for (int j; j<3; j++) {
std::cout << j << std::endl;
}
}
return 0;
}
Above is the simplest example, I could think of, that produces the problem. The expected output is 0, 1, 2, 0, 1, 2, 0, 1, 2, however it only outputs 0, 1, 2 when I compile and run it.
for(int i = 0;.., you are not guaranteed to have zero value there in general. Same with j.