A loop that has a setMethod
for a private variable.
I want this set-method to add value in the first turn of the loop, and then just stop. How can i do that?
Code:
for(int x = 0; x > 5; x++)
{
setnum(5);
cout << getnum();
setnum(getnum() -1);
}
this code should output: 1 2 3 4 5
but when doing it it outputs: 5 5 5 5 5
The setnum(5)
is resetting.
How to prevent it? with setnum(5)
inside the loop.