Reputation: 11727
The following is my code:
bool rValue = false;
for(int i=0; i < 10 ; i++)
{
some code...
...
...
rValue = true
}
std::cout << "rValue is " << rValue << std::endl;
Output of the above code is rValue is false
. Why? Why didn't the value of the rValue variable change?
Upvotes: 0
Views: 243
Reputation: 12904
I suspect somewhere inside your loop you have declaration bool rValue
. So its changing the rValue
under loop scope. not the parent scope one.
and also If you quit the loop before reaching the inner assignment statement it will not effect. You can check that in a debugger or place a std::cout
before assignment
Upvotes: 3