-1
我有這個c代碼,關於多個if語句.. 所有語句都很好地工作,除了最後一個.. 它被其他if語句激活並因此破壞結果.. 任何建議?其他多個if語句
for (i=0; i<(total); i++)
{
for (n=0; n<((total)/4); n++)
{
if (i==(0+(n*4)) && i<(total-5)&&(array[i]==0))
{
array[i]=1;
i=n=500;
break;
}
else if ((i==(3+(n*4)))&&i<(total-5)&&(array[i]==0))
{
array[i]=1;
i=n=500;
break;
}
else if (i==(total)&&(array[i]==0))
{
array[i]=1;
i=n=500;
break;
}
else if (i==(total-1)&&(array[i]==0))
{
array[i]=1;
i=n=500;
break;
}
else
printf("**Something**");
}
}
}
存在C.沒有特殊的'別人if'它只是一個組合。 –
只是將你最後的'else'語句替換爲'else if',你應該沒問題。 **'c' **沒有像其他語言那樣隱含'else if'語句**(例如:Python:'elif')**。 –