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)
                            {
                                tempBoard.push_back(0);
                                cout << "ZERO" << endl;
                            }
                            else if(x != i)
                            {   
                                cout << "X IS NOT I" << endl;
                                cout << board.at(x) << endl;
                                tempBoard.push_back(board.at(x));
                            }
                            cout << "i: " << i << endl;
                            cout << "x: " << x << endl;
                            x = (x + 1);
                            cout << "changed x: " << x << endl;
                        }

Recommended Answers

All 2 Replies

ye problem is right here:

if(x = i)

you seem to be an intelligent individual. take this opportunity to fix ye' error.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.