for(i=max;i;i--) if(!flg[i]) statement;
を
for(i=max;i && !flg[i];i--) statement;
と書くと同じようには動きません。
何故でしょうか。