c++ Variable being overwritten during each loop iteration -
I'm developing simulation software for which some aspects of its functionality require some predefined behavior of an entity The behavior on which I am currently working is establishing a unit in the simulation environment to go to a 'spiral' about the determined point by the user.
There are several current options of user behavior by selecting special options from the GUI, the way I intend to implement this new behavior for the unit is as follows:
< Ul>I have started writing a loop to implement this behavior, and I intend that with each repetition of the loop, by checking the angle of the unit from the original, the number of the entire circuit To increase, every time the angle is equal, as was the connection to the spiral behavior, I will know that another circuit has been completed. But, since I am getting an angle between the unit and the origin at the beginning of the loop, this value will be updated with every move of the loop - this will mean that the unit will not be able to reach the original again from that angle, Because the angle will keep changing.
What would I want to know, if there is a way to set the value of a variable before running a loop, and after that the value of another loop is repetitive? Can I specify that value in a global variable, and make it 'absolute' value, so that even if I try to change its value again I will not be able to?
EDIT
The obvious suggestion is to set that variable variable value outside of the loop, but I can not do this due to the nature of existing behaviors That has been implemented, and then what happens when the user selects one of the behaviors.
It almost feels like you should do the first loop of the loop to set this one time variable Exit the loop , and then repeat inside the n-1
. If the loop body is complex, then put it in a function. Also keep in mind that if you use the floating point value of your angles, then it is likely that they are never the same after the first repetition.
int loop_body (params) Return first_iteration_value; } Int initial_value = loop_body (parameter); For (init; condition; incr) {loop_body (params); }
Comments
Post a Comment