if + else if + else if...のいずれかが実行された場合、コードを実行したいと思います。
if(){
...
}else if(){
...
}else if(){
...
}
//run something if ANY of the above was executed
ifまたはごとに実行したい行を追加することelse ifもできますが、スパムが多すぎます。
私がしたことは次のとおりです。
temp=i;//store a copy
i=-1;//make the change
if(){
...
}else if(){
...
}else if(){
...
}else{
i=temp//restore if none was executed
}
上記は、何に関係なく変更を適用し、この変更を。で元に戻しelseます。これは問題なく動作しますが、このコードの読みやすさが本当に心配です
私が見逃している他のもっと読みやすい選択肢はありますか?