Hi. I am currently writing a block of code to loop through a vector and generate all possible moves on a game. For my first for loop, this block of code never increments x.
I even stuck an x = x+1 at the end of the block and it just resets x to zero. Any ideas as to why this is happening?

// Testing singlular crossouts
                        int x;
                        for(x = 0; x < boardsize; x++)
                            cout << "Board Size: " << boardsize << endl;
                            cout << "reached here" << endl;
                            if(x = i)
                                cout << "ZERO" << endl;
                            else if(x != i)
                                cout << "X IS NOT I" << endl;
                                cout << board.at(x) << endl;
                            cout << "i: " << i << endl;
                            cout << "x: " << x << endl;
                            x = (x + 1);
                            cout << "changed x: " << x << endl;

Edited by da10x: n/a

5 Years
Discussion Span
Last Post by da10x

Oh, I'm sorry. Let me clarify. This is sitting inside another for loop, checking back and forth between them to get every single possible combination. This is just one small part. In my output for this, I'm getting this following input infinite times:

Board Size: 4
reached here
i: 0
x: 0
changed x: 1

As you can see, they are equal, and after I increment it at the end, x is 1, but then gets reset to zero again afterwards.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.