//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 では失敗する可能性があります。