for (int i = 0; i < numOfIterations; i++){
if (this happens){
value = i; //trying to save that particular position
}
//Now the problem is: the value will change in the next iteration.
#include <stdbool.h>
bool setValue = true;
for (int i = 0; i < numOfIterations; i++){
if (this happens && setValue){
value = i; //trying to save that particular position
setValue = false; // Now that setValue is false
// variable "value" will not be set again,
// even if "this happens" is true
} // End of if
} // End of For-loop
for (int i = 0; i < numOfIterations; i++){
if (this happens && i == 0) { //that means if i is equal to 0 and your condition is true, code will be executed
value = i; //trying to save that particular position
}
}
3条答案
按热度按时间iovurdzv1#
hm2xizp92#
最简单的方法是
eagi6jfj3#