For loop (inside while loop) is being ignored

716 views Asked by At

I have two for loops inside a while loop but when I execute the program, the while loop just becomes an infinite loop. Here is my code:

    while (!inFile1.eof()){

       for (int row = 0; row < 5, row++;){
            for (int column = 0; column < 5, column++;){

            getline(inFile1, fileData, (','));

            matrix1[row][column] = stoi(fileData);

            cout << matrix1[row][column];

            }
        }       
    }

I'm new to C++ so maybe I have made a silly error but I'd appreciate any help

1

There are 1 answers

0
Bathsheba On BEST ANSWER

You have stray commas in your for loops, which you should replace with semicolons:

int row = 0; row < 5; row++;

int column = 0; column < 5; column++;

Currently the stopping condition is row < 5, row++, which is the same as row++ due to the way in which the comma operator works.

Eventually your int will overflow and then you're in undefined behaviour land.