//Initialize
i=0;
foreach(runs 8 times) {
if(some condition that sometimes happens) {
$i = $i + 3;
} else if (some other condition that sometimes happens) {
//Do nothing with i
} else if(some condition that sometimes happens) {
$i = $i -4;
}
if(what condition do i put here to check if $i changed from the start of the loop?) {
//nothing changed, do action 1
} else {
//Else something changed and do action 2.
}
}
嘿,伙计们,我确定这很明显,但是我很难使用这个算法,每次我需要确保 $i 与循环开始时不同并执行行动 1 或行动 2 基于该区别。
对于第 1 次迭代,我可以输入 if($i == 0) {,但随后在第 2 次和第 3 次迭代中可能会失败。