の 3 つの条件if
は選択肢であり、if-else if-else
チェーンに変換する必要があります。割り当てのようなステートメントc,i,v := c+2, i+1, b[i]
は、私が知る限り、Python の複数の割り当てのように複数の割り当てであるため、i
inb[i]
は の古い値を参照しますi
。それがもたらす
// n and v are initialised to something sensible, hopefully
i = 0;
c = 0;
while(i != n) {
if (b[i] == v) {
c = c + 2;
i = i + 1;
} else if (c == i) {
c = c + 2;
v = b[i]; // conjecture that the b[i] on the RHS refers to the old i
i = i + 1;
} else {
i = i + 1;
}
}
はすべてのブランチでインクリメントされるためi
、それを持ち上げて取得できます
for(i = 0, c = 0; i != n; ++i) {
if (b[i] == v) {
c += 2;
} else if (c == i) {
c += 2;
v = b[i];
}
}